ReadOnly DataGridView with EditableRootListBase binding?

ReadOnly DataGridView with EditableRootListBase binding?

Old forum URL: forums.lhotka.net/forums/t/2936.aspx


dcleven posted on Wednesday, May 23, 2007

I am using CSLA 2.1.4. I have an EditableRootListBase collection bound to a DataGridView. Based on the user login the DataGridView is editable or readonly. The CanEditObject call works correctly and prevents edits for the readonly users, but the Save method on the root object is called every time I navigate to another row in the grid. How can I prevent trying to save when the user has readonly access? I have tried setting the grid to ReadOnly and that does prevent changing data but still when changing rows the bindingsource thinks it needs to call EndEdit, which calls Save which throws the "Cannot Edit" exception which pops up the message in my UI, not the best workflow for a user.

Thanks

Doug Cleven

RockfordLhotka replied on Wednesday, May 23, 2007

You should be able to override SaveItem() in your collection class:

Public Overrides Sub SaveItem(ByVal index As Integer)

  If MyCollectionType.CanEditObject() Then
    MyBase.SaveItem(index)
  End If

End Sub

 

Brian Criswell replied on Wednesday, May 23, 2007

You could override save in your object so that if the object has not changed it aborts the save.

EDIT: Never mind, Rocky answered it.

Copyright (c) Marimer LLC