Hi
We have some code that performs an action as soon as the user ticks a field in a grid.
I'm forcing the update to happen as soon as the cell is ticked using:
And allowing the user to cancel the action with this code:
This very nearly works perfectly, the only glitch is that if the user chooses to cancel the update the checkbox is still un-checked. This is only a UI thing, the value in the underlying object is correctly unchanged and as soon as the the user moves cell/row the cell then flicks back to being checked again.
Is this expected behaviour? Is there anyway to force the cell to reload it's value from the datasource when the change is cancelled (without reloading the entire grid)?
Hi Tom,
Frankly, I'm not sure if this is a bug or not. The cancel operation is working correctly, but the display isn't updating. It might just be because the cell is still active and in edit mode.
If you want, I can ask Infragistics Developer Support to write this up for developer review, but even if this is a bug, I'm not sure it's something that could be fixed without a large potential for breakage. So the easiest thing might be for you to work around it. I found a pretty simple and easy workaround:
Private Sub LocalityDRLUltraGrid_BeforeCellUpdate(sender As Object, e As BeforeCellUpdateEventArgs) Handles LocalityDRLUltraGrid.BeforeCellUpdate Select Case e.Cell.Column.Key Case "Boolean 1" If e.NewValue = False Then e.Cancel = (MessageBox.Show("Marking a locality as non-current will automatically mark all associated GP practices as non-current. Do you wish to continue?", _ "Mark locality non-current", MessageBoxButtons.YesNo) = DialogResult.No) If (e.Cancel) Then e.Cell.EditorResolved.Value = True End If End If End Select End Sub
That looks good, thanks Mike. Am I right in saying that setting e.Cell.EditorResolved won't cause a write to the underlying object, i.e. is it just updating the UI presentation?
Hi Mike
Ah right, so not at all what I thought!
Thanks for that, that seems to solve it. What I have belatedly realised is that another solution is just to call grid.PerformAction(UltraGridAction.ExitEditMode), that seems to cause it to update correctly too. I can actually use that for both the BeforeCellUpdate and the CellChange, so the code becomes:
If (e.Cancel) Then Dim grid As UltraGrid = e.Cell.Row.Band.Layout.Grid grid.PerformAction(UltraGridAction.ExitEditMode) End If
Well... it's basically the same as the user changing the value through the UI. In this case, I don't think it will write tot he data source, since you are setting it to the same value the data source is already set to and you cancelling, which doesn't happen until after the event completes, anyway.