We have an MVVM application which uses a XamGrid (v12.1) bound to a BindingList. When a cell in the XamGrid is modified, the View needs to notify the row index of the modified cell to the View Model. For this, I used the CellExitedEditMode event to get the row index as follows:
void OnCellExitedEditMode(object sender, CellExitedEditingEventArgs e)
{ int rowIndex = e.Cell.Row.Index; }
The above code stops working after the user performs a sort operation. After the XamGrid is sorted, the row index obtained using the method above is not the same as the row index from the BindingList.
Hello Koshy,
Thank you for your post. I have been looking into it and I can suggest you use the following code in order to get the index of the currently edited item directly from the BindingList, where the indexes doesn’t change:
int index = (sender as XamGrid).ItemsSource.OfType<object>().ToList().IndexOf(e.Cell.Row.Data as ChartData);
where "ChartData" is your data type. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Hi Stefan,
Thanks for the response. Your solution is correct and works.
A performance issue with this solution is that the IndexOf operation involves scanning the list to find the row index. It would be nice if the XamGrid provided some internal support to keep track of the row index.
Thanks,
Koshy