Ticket T852231
Visible to All Users

How to check if any data in a GridControl row has changed

created 5 years ago

Hi,

Is there any possibilty to check if some data in the inline editor was changed or not?

Currently I set a dirtyFlag in my ViewModel if the EditFormShowing Event is fired.

What I need now is a place where I can reset this flag if editing was canceled.

But there seems to be no event for canceling the editing of an existing row.

If I cancel editing a new row there is the "RowCanceled" event.

Why is there no event for clicking the cancel button in the inline editor?

Answers approved by DevExpress Support

created 5 years ago

Hello Andreas,

We described why GridControl does not raise RowCanceled when the Edit Form's Cancel button is clicked and how to handle this moment in this thread: T435547 - RowCanceled Event is not fired when EditForm is used. Please take a moment to review it.

I'd like to note that our GridControl can operate with data items that implement the IEditableObject interface. I recommend that you try implementing this interface in your data item class. This will allow you to receive notifications when an end user commits or discards changes in data rows.

Just in case, check to see if our new Edit Entire Row feature is suitable in your scenario.

Thanks,
Andrey

    Show previous comments (3)
    Kirill (DevExpress Support) 5 years ago

      Hello Andreas,
      Let me slightly clarify the ways which our GridControl uses to edit rows.

      There are two row editing approaches:

      1. GridControl edits a real object. That means that it immediately sends values of cells to a data item when they are changed and posted in the UI.
      2. GridControl edits a proxy object. With this approach, GridControl edits values at the proxy object level and posts them to a corresponding row object only when you manually force this action. For example, when you leave the edited row, click the "Update" button etc.

      The RowCanceled event was designed only for scenarios when a real row object is modified and these changes are discarded. When the "Entire Row Editing" or "Edit Form" functionality is used, the underlying data object is not modified until the "Update" button is clicked. That's why the event is not raised. The only exception is the "Immediate" EditFormPostMode value - in this mode, the Edit Form doesn't use a proxy object and immediately posts changes to a corresponding row object.

      As there are different editing approaches in GridControl, there is no universal way to catch the moment when you cancel editing in all possible cases. If you're going to edit data in GridControl using only the Edit Form (in different modes), I suggest that you use the approach we demonstrated in the How to catch the Update button click in the EditForm thread. I see that we already suggested it in one of your previous threads: T852156.

      Thanks,
      Kirill

        Hello Kirill,

        thanks for your detailed explanation.

        As I understand it now, I have to handle following events in order to be able to clearly recognize whether editing (no matter which editing mode) has started respectively editing has ended (regardless of whether an update or a cancelation occurs):

        - ShownEditor
        - EditFormShowing
        - EditFormClosed (implemented with a descendant TableView and EditFomOwner as shown in How to catch the Update button click in the EditForm)
        - AddingNewRow
        - RowUpdate
        - RowCanceled

        In the associated event handlers I currently set a flag that shows whether the editing is in progress or has been ended. I then use it to control whether navigation to another page is permitted or not.

        Is this the correct way or is there an easier way?

        DevExpress Support Team 5 years ago

          Hello,

          As for the set of events, you can handle them in your application and, as my colleague Kirill mentioned, there is no universal way to catch the moment when you cancel editing. I would like to add that if you wish to catch the moment when a cell value is about to be changed, you can also handle the CellValueChanging event. To catch the moment when a cell value has already been changed, handle the CellValueChanged event. This event is fired for in-place editing only.

          If you are using the MVVM pattern, you can create a custom behavior for your GridControl/TableView and subscribe to all the necessary events there.

          Should you have additional questions, let us know.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.