0

I have some code that finds a bunch of rows based on a search criteria and then finds the index of one of those rows. This works fine with a DataTable

Dim drRows() As System.Data.DataRow = dt.Select(vstrSearchCriteria)
If drRows.Length > 0 Then
    Dim intIndex As Integer = Me.Rows.IndexOf(drRows(0))

However, I'm trying the same on a DataView but I can't seem to relate the identified rows back to the DataView - there is no .IndexOf and even iterating through doesn't seem to match the ToTable row with the original Row.

NB the search criteria can be complex and isn't based on keys

Dim drRows() As System.Data.DataRow = dv.ToTable.Select(vstrSearchCriteria) 

For i As Integer = 0 To dv.Count - 1 
    If dv(i).Row is drRows(0) Then

I need to find the dv(x).Row that is the row found by the .totable.select

Many thanks

  • Why the call to ToTable? This creates a new table duplicating columns and rows but this new columns and rows while having the same content are not the same object instance of the first DataTable. The DataView has a property called Table that should work for you – Steve Jun 10 '16 at 08:40
  • thanks but .table doesn't return the rows in the dataview sort / filter order as far as I'm aware - and dataview doesn't support .select . I've implemented a workaround at the moment that goes through each dataviewrow.row and uses sequenceequals to compare with the row I'm looking for but obviously performance will be pretty poor – Rob Morgan Jun 10 '16 at 11:51

0 Answers0