Hi,
I'm using a XamDataGrid with the ActiveRecord bound to an element of my ViewModel. When the element of the ViewModel changes, the ActiveRecord changes accordingly and the appropriate row is activated in the grid. Now I need to prevent the user from manually changing the ActiveRecord away from the bound value.
With my current attempt, the user is unable to change the ActiveRecord by clicking on a row, but after clicking on a row, further changes to the ViewModel element are no longer reflected in the grid. If the user then clicks a second time on the grid, the grid's ActiveRecord will then snap back to the element from the ViewModel.
Is my implementation on the right track? Where am I going astray?
private void grid_RecordActivating( object sender, RecordActivatingEventArgs e){ Element currentElement = null; DataRecord currentRecord = null; if (ViewModel.getInstance().CurrentElement != null) { currentElement = ViewModel.getInstance().CurrentElement; currentRecord = grid.GetRecordFromDataItem(currentElement, true); } if (currentElement == null) { e.Cancel = true; } else if (e.Record != currentRecord) { e.Cancel = true; currentRecord.IsActive = true; } else { currentRecord.IsSelected = true; }}
private void grid_RecordActivating( object sender, RecordActivatingEventArgs e){ Element currentElement = null; DataRecord currentRecord = null; if (ViewModel.getInstance().CurrentElement != null) { currentElement =
ViewModel.getInstance().CurrentElement; currentRecord =
grid.GetRecordFromDataItem(currentElement, true); } if (currentElement == null) { e.Cancel = true; } else if (e.Record != currentRecord) { e.Cancel = true; currentRecord.IsActive = true; } else { currentRecord.IsSelected = true; }}
Thanks Matt,
That worked just fine.
HI,
I am just following up on this post.
Please let me know if you need additional assistance.
Sincerely, Matt Developer Support Engineer
I am attaching a sample application, that prevents the ActiveRecord from changing if a checkbox is not checked. Once the checkbox is checked, the ActiveRecord can be changed.
I am reviewing your issue.
Marianne,
This doesn't work either. The RecordDeactivating event gives a similar effect as when I tried the RecordActivating event. In both cases, after a mouse click anywhere on the grid, the ActiveRecord stops tracking the bound property. This is the case even with PreviewMouseDown always setting e.Handled to true. Plus, the active row can still be changed by tabbing into the grid, then using the arrow keys for navigation.
I like your product, but if I can't get this to work I'll be forced to switch to another vendor. Surely I'm not the first person to come to you with this requirement? Any other ideas?