I've got a grid that I'm applying a datasource to in code. I need to setup insert/update/delete commands. When I do one of these ops, which is the best event to attach the save code?
Thank you Sean for contacting us today.
Please refer to the following blog regarding advice for CRUD operations and the events you can hook and perform your save.
https://ko.infragistics.com/community/blogs/b/kiril_matev/posts/implementing-crud-in-the-infragistics-xamdatagrid
Sure, but it looks like those rely on creating an actual datasource and having a model. I've just got a datatable being returned from the DB. And I'm using that in 100 places in the app so I can't change methods.
I meant the grid events. It shouldn't matter the type of datasource you are using.
Well, that's what I thought, but the 3 event methods in that article ( RecordAdded, RecordUpdated, RecordsDeleted) aren't in the events list for the grid. I've attached a pic. What am I missing? The list is alphabetical so they should be in the visible list in the pic.
AfterRowUpdate, AfterRowsDeleted, AfterRowInsert
Ok, I'm getting back to this now. I found the methods and I'm able to bring up a message box when they're called, so I know when they're called. However, there are still 2 issues:
1. When using the message box inside AfterRowInsert, it fires as soon as I click in the field to add a value for the new row. I thought it's supposed to only fire after the insert. It also fires when I hit enter to go to a new row, but it shouldn't fire when I simply click in the cell.
2. I can't seem to access the data in that new row. I've looked at the active row and that's not it. So how do I get those values I just entered?
Thanks for the assist Mike. Sean, you are probably interested in calling AcceptChanges on the DataTable, explained in the DataAdapter doc above.
If the grid is bound to a DataTable, then the table will automatically be updated by the grid. You don't have to manually copy the data from the grid into the DataTable.
Typically, you would use a DataAdpater to get your data from the DataBase into the DataTable and to write the changes back to the DataBase from the DataTable. That part doesn't even involve the grid, so it's not something we document, but I'm sure there is documentation on the DataAdapter provided by Microsoft.
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/updating-data-sources-with-dataadapters
Well, I only want to save what's in the row because I don't know any other way. Access the row, assign each cell a var, send the insert stmt to the DB.
How should I be doing it? Again, if you've got an example that shows what I should be doing I'd love to see it. I've looked all over and I can see all types of things that can be done, but nowhere that shows how to simply save a new/updated row to a DB.
AfterRowInsert will never show you the new data, because there is no new data at that point. This event fires as soon as the AddNew row is created. So that's before the user has had a change to change any values in the row.
If you want to retain what is in the add new row you can set grid.RowUpdateCancelAction = RowUpdateCancelAction.RetainDataAndActivation;