Hello,
I have a form with an Ultragrid that is used to show data that can be modified.
When the user clicks the save button, there is code to force the Ultragrid to lose focus so that any pending changes are committed.
My issue is that I am running a method when the user clicks the save button with the assumption that there were changes made to the Ultragrid.
In reality, most of the time the save button is click, there are no changes to the Ultragrid and I am running this method unnecessarily.
I'm looking for a way to determine, when the Ultragrid loses focus, if there were any pending changes prior to losing focus.
I'm hoping that someone can point me in the right direction.
Hi,
Instead of forcing the grid to lose focus, you could just call the Update method. This should be very efficient, since the grid already knows what needs to be updated.
In theory, there should only be one row in the grid with pending changes, since moving from one row to another commits the changes on the previous row. So if you want to know if the grid has pending changes, you could do something like this:
UltraGridRow activeRow = this.ultraGrid1.ActiveRow;bool hasChanges = activeRow != null && activeRow.DataChanged;
I say "in theory" here, because it actually is possible to have changes in rows other than the ActiveRow - but only if you change the data in code. In other words, the user can't do it - they can only change the activerow. But you could change the value of some other row programmatically.
Hi Mike,
Your example worked well. Thanks for the advice. I'm grateful for the help.