I'm using a data grid that has its data source replaced programatically from time to time based on user selections. I've tried every suggestion I can find in the forums to force a refresh of the data and its layout without success. I'm using the latest 7.2 hotfix (7.2.20072.1007).
The grid uses AssigningFieldLayoutToItem and RecordExpanding to arrange for layout and, sometimes, content based on individual record state.
The symptom is that all rows that were previously there retain their original values, but they are not active (you cannot select or expand them). If the new list is longer, the new rows appear and are active.
The only way to get it to "fix", is to switch away from the containing tab item (its in a tab control) and back, manually. This causes it to show the correct data. (Not a suitable solution, just a symptom).
I noticed a comment stating there was a bug. Perhaps it's still there in this context. Is there some way to get the grid to "start over" when we replace its data source with a different object?
At this point, I'm seriously considering dropping the use of this library. It's lack of certain features and/or the presence of bugs and problems like this makes it not worth it.
Dave
I can send you code, but you won't be able to run it. I can't send you the entire system or its data. Perhaps the excerpted code will give you more context. I'll send it seperately.
I spent some time trying to create a small must-fail sample, but that didn't work out either. In doing so, I discovered another potential work around, and hopefully another clue.
Binding binding = new Binding();binding.Source = thedataobject;this.dataGrid.SetBinding(XamDataGrid.DataSourceProperty, binding);
By wrapping the setting in a binding, the grid shows the correct data. Interestingly, I used DataSource={Binding} and set the DataContext above it, without success. (But that time, I didn't try the binding wrapping.)
Thanks for looking at this.
Thanks Dave for posting your work-around. Is there a way you can make the broken part of the code available to me so I could run it and see if I can get you a solution that doesn't feel like a hack to you? You can email me the code directly if you prefer to not make it available to all our users.
Thanks
Curtis
ctaylor@infragistics.com
For what its worth, I have a work around to my own problem. I consider it a hack, but it may give some clues to the problem.
Basically you need to let the dispatcher have some time to do things before you can replace the data source, after you have null-ed out the original data source. This is analogous to windows forms message loop DoEvents concept.
Instead of:
this.dataGrid.DataSource = null;this.dataGrid.DataSource = somenewobjectthathasthedata;
Do this:
this.dataGrid.DataSource = null;Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(DataSourceRefreshHack));
...
private void DataSourceRefreshHack() { this.dataGrid.DataSource = somenewobjectthathasthedata;}
Priority must be Background to give all other actions time to complete. If you try to give it higher priority you get the same symptom as before.