G
Guest
If I create a DataView(i.e. dv) with a particular RowFilter and Sort, I
realize that I can't use a For Each to delete those rows because each
deletion changes the current view.
So that this won't work:
dim drv as DataRowView
for each drv in dv
drv.delete()
next
If however I collect an array of DataRowViews by using the FindRows of the
DataView and then using a snippet such as this(which deletes the rows in
reverse order) the deletion of the group of filtered rows works fine:
Dim dv As New DataView(TheTable, TheRowFilter, TheSort,
DataViewRowState.CurrentRows)
Dim drv() As DataRowView = dv.FindRows("SortKey")
For x = drv.GetUpperBound(0) To 0 Step -1
drv(x).Delete()
Next
However, this seems more complicated that it should be.
Therefore, what is the best way to delete all the rows in a particular
DataView?
realize that I can't use a For Each to delete those rows because each
deletion changes the current view.
So that this won't work:
dim drv as DataRowView
for each drv in dv
drv.delete()
next
If however I collect an array of DataRowViews by using the FindRows of the
DataView and then using a snippet such as this(which deletes the rows in
reverse order) the deletion of the group of filtered rows works fine:
Dim dv As New DataView(TheTable, TheRowFilter, TheSort,
DataViewRowState.CurrentRows)
Dim drv() As DataRowView = dv.FindRows("SortKey")
For x = drv.GetUpperBound(0) To 0 Step -1
drv(x).Delete()
Next
However, this seems more complicated that it should be.
Therefore, what is the best way to delete all the rows in a particular
DataView?