Current filter:
                                You should refresh the page.
                                Support Center
                                  • Hi, i'm new at using windows forms... I normally allways build a web application.

                                    Now i have a question about how to save changes made to a record displayed in a LayoutView of the XtraGrid.

                                    In the web i do this as following:
                                       1. Create the gridview, assign the Fieldnames to the columns, assign the Update & Insert & Delete Methods (OnRowInserting, OnRowUpdating, OnRowDeleting)
                                       2. In code behind set the datasource for my gridview and handle all changes their when the user press the Update/Delete/Insert buttons

                                    Now how can i do this with the XtraGrid?

                                    As there is no edit button, i created my own add & delete button which works fine.

                                    But the problem is with at the Edit site...

                                    How can i create my own update method for the XtraGrid, my datasource is a simple List<T>

                                     gridControl1.DataSource = AlgemeenGegevenManager.GetPersonen();

                                    public static List<AlgemeenGegeven> GetPersonen()
                                              return AlgemeenGegevenDA.GetAlgemeneGegevens();

                                    Is there any property that keeps track of the record being changed, which i then could check when the user closes the form OR navigates to another record. If that property is true then i would save the record using my own custom update method...

                                    Is this possible?

                                • Hello Tom,

                                  Changes made in XtraGrid are posted to its datasource automatically. If you want to perform some custom operations when they are posted, use the ColumnView.RowUpdated event. Please let me know whether it is helpful.


                                • Tom Procureur_1 07.07.2010

                                  Well, how will this then get saved to the Database...

                                  I know that when i change a record, that these changes are saved inside my Datasource, which is a list of type List<AlgemeenGegeven>()

                                  But how do you save the changed to your datasource inside your database ? Which method do you have to use for this?

                                • Hello Tom,

                                  XtraGrid doesn't provide such a method. It is intended to only work with a datasource, passed in it. So, you should write changes to the database at some moment yourself, for example, in the RowUpdated event handler, or when the Save button is clicked. In the second case, you should call the PostEditor and UpdateCurrentRow methods, as shown in the Posting Data to a Connected Database help topic.
                                  If you are interested in what capabilities DevExpress provides to store values of business objects (AlgemeenGegeven in your example) to the database, you'll find our XPO library useful. Please refer to the eXpress Persistent Objects Home help topic to learn more about it.
                                  Please let me know if you need any further help.


                                • Tom Procureur_1 07.07.2010

                                  Is that just something like this ?

                                  private void layoutView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
                                              if (e.Row != null)
                                                  AlgemeenGegeven algGeg = (AlgemeenGegeven)e.Row;

                                  If the saving fails, should we just position the layoutView back to the changed item using the e.RowHandle index?

                                1 Solution

                                Creation Date Rating Importance Sort by

                                Hello Tom,

                                If saving fails, and you require rolling back changes, there are two approaches:
                                1. Consider saving it as a transaction. In this case, when it fails, and it is required to rollback changes, you should reload all objects from the datasource, i.e. reset grid.
                                2. Save each row separately. In this case, when saving fails, you should reload only the current row. When this approach is used, the RowUpdated event isn't quite appropriate for saving data. It is better to implement the IEditableObject interface in your business class (AlgemeenGegeven), and save the object in its EndEdit method. I've created a small sample, demonstrating how to use this interface. Please let me know whether it is helpful.

                                BTW, XtraGrid provides built-in validation capabilities. Please review the Input Validation help topic, to learn about them.


                                If you need additional product information, write to us at or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners