I have an UltraGrid
in my project, and I have an update function on the form to update the data in the database where the data is matching.
The data in the grid is being stored as a DataTable
. If a row of existing data is deleted from the UltraGrid
, I want to be able to set the RowState
of that row in the DataTable
to 'RowState.Deleted, so that in the Update function I can check the
RowState`, and if it's a deleted row, then deleted it, otherwise, update the data.
How can I go about doing this? So far, I have the code below, but the count of rows being returned is 1 (or, the current number of rows in the grid) and not 2 (the number there was before I deleted one row).
How and where in the code, do I set the RowState
of the deleted row to be RowState.Deleted
? Is there an alternative way of doing it using the UltraGrid
?
dsProducts.Tables.Add(commDt.Copy) -- commDt is the DataTable linked to the UltraGrid
tr = con.BeginTransaction(
For Each dr As DataRow In dsProducts.Tables(0).Rows
If dr.RowState = DataRowState.Deleted Then
Try
Solved it.
Declare a DataTable
at the top of the class
On the BeforeRowsUpdate
method, insert a new row into the DataTable
, which are the values of the row being deleted.
Optionally, include a confirmation box to ensure they wish to delete the row. If they cancel the deletion, remove the row from the DataTable
.
This DataTable
can then be used for deleting rows in the UPDATE
query, whilst the grid DataSource
can handle the UPSERTS