Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
Blocking user changes to ActiveRecord
posted

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;
    }
}