David David - 10 days ago 5x
Vb.net Question

Set RowState of a DataTable row to deleted

I have an

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
. If a row of existing data is deleted from the
, I want to be able to set the
of that row in the
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
of the deleted row to be
? Is there an alternative way of doing it using the

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


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