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()
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?
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.
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?
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.
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?
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.
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.