Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Query columns from a table to be shown in a datagridview

$
0
0

Hello Community,

I am currently using the code below in order to fill my datagridview. However, my datagridview will display columns I do not need to be seen. Also,  I am using Entity Framework 5 DbContext API. DbSet<T>.ToList()

TrialEntities db =newTrialEntities(); dataGridView1.DataSource= db.Resistors.ToList();

When I use the code below to use specific columns I run into various issues with editing from another form back to the main form with a datagridview. This is because in order to refresh my datagridview I call the query again. This causes my edits to be lost, but that is not the case with the previous code above.

varQry=(from R in db.Resistorsselectnew{ResistorID= R.ResistorID,
           RTC_PN = R.RTC_PN,Description= R.Description,KeyValue= R.KeyValue,SymbolID= R.SymbolID}).ToList();
dataGridView1.DataSource=Qry;

Is there a way to select the columns to use without having to select new? Should I be using something other than ".ToList" maybe? Is there a better way to go about refreshing my datagridview that won't lose my edits?

I am new with C# and any help would be greatly appreciated. Thank you!


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>