Hello, I have a datatable with data as below:
I am using pure MVVM, I cant do code behind to refresh the grid. Also, grid data source binding mode is set to TwoWay.
Any help is greatly appreciated.
Matt, Your solution worked but required lot of hack in the code. Reason is,
1) I use Observable collection to bind to the grid and also use pure MVVM.
2) Data is getting updated in the ViewModel which doesnt know anything about the grid. So, I cant call RefreshSort from ViewModel. Lets break the rules, I subscribed to the RecordsInViewChanged event and then subscribe to CollectionChanged, Grouped events.
3) The above doesnt help.. because I am only editing the existing collection object.. ouch.. so, I threw some more ugly code in the viewmodel.. any time value for an object changes... remove the object and re-insert it...
after doing all these things. it worked now.
Code behind:
private void _someGrid_RecordsInViewChanged(object sender, Infragistics.Windows.DataPresenter.Events.RecordsInViewChangedEventArgs e) {
if (e.Source != null) { ObservableCollection<ModelObject> col = ((DataPresenterBase)(((RoutedEventArgs)(e)).Source)).DataSource as ObservableCollection<ModelObject>;
if (col != null) { col.CollectionChanged -= new NotifyCollectionChangedEventHandler(col_CollectionChanged); col.CollectionChanged += new NotifyCollectionChangedEventHandler(col_CollectionChanged); } }
}
void col_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (_groupingEnabled) { _someGrid.Records.RefreshSort(); } }
private void _someGrid_Grouped(object sender, GroupedEventArgs e) { _groupingEnabled = e.FieldLayout.HasGroupBySortFields; }
ViewModel:
int index = QueryResults.IndexOf(SelectedItem);
if (index != -1) { QueryResults.RemoveAt(index);
QueryResults.Insert(index, obj);
HI,
I am just following up on this forum thread.
If you need further assistance, please let me know.
Sincerely,
Matt, Developer Support Engineer
You could call the XamDataGrids RefreshSort() method. xamgrid1.Records.RefreshSort();
Here is a blog post on the RefreshSort Methodhttp://blogs.infragistics.com/forums/t/32118.aspx
Sincerely, MattDeveloper Support Engineer
Matt, Thanks for your reponse.
But, it doesnt help in my case, because I am not editing the cell. As I mentioned, value gets updated in a seperate window.
Why wouldnt the grid know that the underlying data changed and refresh accordingly..
You need to call the RefreshSortPosition method. I would call it after the CellUpdated Event.
Here is a code snippet:
e)
{
// throw new NotImplementedException();
e.Cell.Record.RefreshSortPosition();
Here is a another forum thread addressing this issue
http://forums.infragistics.com/forums/p/42422/234312.aspx#