Hey there,
I am running into issues using a DataGrid under .net 4.0 (I apparently haven't had these issues on 4.5, however am forced to use 4.0).
I'm filling a DataGrid with a joined MS Access Table using OleDb.
First off I store the result of my query in a datatable. In this datatable everything is fine, correct values are shown for all columns.
My DataGrid has nothing special in xaml, except for "AutoGenerateColumns="True"" hence I leave that out. Coming from WinForms, I am used to doing everything I need during runtime in the code itself.
Now binding that table to the datagrid is where the problems occur:
dataGrid.ItemsSource= dataTable.DefaultView;// .DataContext = dataTable; wouldn't work
Oddly, all column content from the first table of my join query is shown, while all columns from joined tables do not display any content - allthough the datatable has all content properly in those columns.
Additionally, if I edit values in columns of joined tables (only in those) in the DataGrid during runtime, an error comes up: "Two-way binding requires Path or XPath."
This would also work perfectly fine in .net 4.5, I've already tried it out.
So, in 4.0, I tried using a ViewModel, which works for displaying the data:
publicclassViewModelDataGrid:INotifyPropertyChanged{publicstring strColumn1 {get;set;}publicstring strColumn2 {get;set;}// this would be a column of a joined tablepublicstring strColumn3 {get;set;}publicstring strColumn4 {get;set;}// this would be a column of a joined table// the following I simply tried as I don't know how to catch changespubliceventPropertyChangedEventHandlerPropertyChanged;protectedvoidNotifyPropertyChanged(String info){if(PropertyChanged!=null){PropertyChanged(this,newPropertyChangedEventArgs(info));}}}
Now the content just displays fine, all columns are filled - however I cannot catch the event when the user edits a cell. I thought this would work with the EventHandler above however it doesn't. Further more, I need those changes applied to my actual DataTable, as later on I gna update the Access db with that table.
Can anyone tell me the best approach?
Also, why do I have to use .ItemsSource, instead of .DataContext?