I set the grid's UpdateMode to OnRowChangeOrLostFocus and it works fine unless I have a context menu on the row that updates a cell value. The row just stays in edit mode. In fact I can edit several rows and they all stay in edit mode unless or until I call row.Update(). The context menu just brings up an edit or copy choice that let's me edit the cell in a special xml text dialog so I have a larger edit area. When I close the dialog, I update the cell's value if anything changed in my edit dialog. Works if I call row.Update() after changing the cell value but that commits the edit for the row without allowing ESC to cancel the edit. Why doesn't UpdateMode=OnRowChangeOrLostFocuswork if I switch to another row? I have debugged that property is still set when I return form the dialog and changed the cell value.
- Dave
Hi Dave,
I'm not sure I follow you. Regardless of the setting of UpdateMode, changing the active row in the grid has to update the grid's underlying data source. The BindingManager will do this automatically, assuming SyncWithCurrencyManager on the grid is true. So the grid could not prevent those updates from taking place even if it wanted to.
So if you are somehow updating the active row and moving away from that row and the row changes are not committed to the data source, then something very strange is going on.
Perhaps this is a result of the fact that you are changing the cell values in code, rather than through the UI of the grid. I would think it would still work, but it might depend on exactly how you are updating the data. Are you setting the Value on the grid cell? Or updating the data source directly?
I think what you might need to do is use the SetCellValue on the row so that the grid simulates a user update to the row, but I have not tried it.
P.S. The row I change stays in edit mode with the little pencil icon. In fact I can have several rows in edit mode and none of them leave edit mode till I hit ^U which in my app is wired to grid.Update().
Using SetCellValue also allowed multiple rows to stay in edit mode with none updating when changing rows. Setting the row active when I clicked the cell with the mouse did the trick. Not sure if you want to consider this a bug but moot to me at this point. Thanks, Dave
No, this is not a bug. I assumed you were already setting the row as active when you showed your context menu which is why I was so confused.
OnRowChangeOrLostFocus means that the focus moves away from the row that was edited. If that row was not the ActiveRow, then changing rows or losing focus from the grid will not do anything. It's designed to handle user updating. If you are updating the data in code behind the grid's back (so to speak), then the grid should not automatically update the data when it loses focus - that would not make sense.
Works for me. Thanks!