How can I use a dataviews .Find method to get the index of a row with composite key?
Posted on 2004-04-19
I have been trying this code to get the index:
Dim dv As DataView
Dim pk(1) As Object
dv = New DataView(ds.Tables("custOrderItem"))
dv.Sort = "orderid, menuItemId"
'Find the custOrderItem matching orderId and menuItemId
With dr 'a reference to the row I am working with
pk(0) = .Item("orderid")
pk(1) = .Item("menuItemId")
i = dv.Find(pk)
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & ex.GetType.ToString)
orderId & menuItemId have values such as 1,2,3,4,5......
I need the index of the specific row so I can change the bindingContext .Position to match this row.
This code works sometimes, but then other times it gives me the wrong index. Always when I'm looking for certain row(s) index it gives me the wrong index.
Is there any way to make this more reliable??