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
How to determine if an Ultragrid has pending changes
posted

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.

  • 469350
    Verified Answer
    Offline posted

    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.