How To Display Data From Related Tables In A Wpf Datagrid
I'm just finding my way with WPF/Datagrid/Linq and I'm trying to find out how to display data from a related table in my datagrid. For example I have 3 tables: Customers: id, na
Solution 1:
I typically just set the DataGrids ItemSource to a DataTable in the code behind. This is easier than XAML if you are going to be changing the ItemSource between more than one DataTable.
myDataGrid.ItemsSource = myTable.DefaultView;Anytime I want to change what my datagrid is showing, I simply update the ItemsSource. That way I can manipulate my DataTable's in any way I want, and then see the outcome via the DataGrid.
Update
To join data from both tables run a Linq join to create an IEnumberable of fields you want in your table. Then convert your IEnumerable back to a DataTable for display. I use this method to convert an IEnumerable to a DataTable.
Post a Comment for "How To Display Data From Related Tables In A Wpf Datagrid"