c# - Best way to bind DataGrid to generic list in WPF -


i trying bind datagrid generic list in wpf.

the following code results in blank rows each row of data in list (i.e. if have 5 rows, shows 5 rows, doesn't shows data in cells):

list<datarow>  databindingsource = guestlist.where(row =>   (row.field<long>("fk_group_id") == int64.parse(cmbgroup.selectedvalue.tostring())) &&   (row.field<long>("fk_age_group_id") != (int)l_age_group.child))   .tolist();  gvwaddultdetails.itemssource = databindingsource; 

if convert list of objects datatable, works (shows data). example:

list<datarow> databindingsource = guestlist.where(row =>   (row.field<long>("fk_group_id") == int64.parse(cmbgroup.selectedvalue.tostring())) &&   (row.field<long>("fk_age_group_id") != (int)l_age_group.child))   .tolist();  gvwadultdetails.itemssource = databindingsource.copytodatatable().defaultview; 

but if had list<datarow>, how convert datatable?

what best practice binding datagrid `list' in wpf?

one way bind datagrid generic list in wpf:

mainwindow.xaml.cs

grid.datacontext = databindingsource; 

mainwindow.xaml

<datagrid   autogeneratecolumns="true"   itemssource="{binding}"   name="grid" /> </grid> 

but won't work datarow, because in wpf, if want bind something, needs property.

- other thoughts -

here's how can convert generic list datatable:

how bind datagrid generic list in wpf:

especially (a great feature in wpf):


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -