Solved

How can I use a dataviews .Find method to get the index of a row with composite key?

Posted on 2004-04-19
2
362 Views
Last Modified: 2010-04-24
Hi,
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")
        End With
        Try
            i = dv.Find(pk)
        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & ex.GetType.ToString)
        End Try

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??

Thanks.
0
Comment
Question by:Tiare
2 Comments
 
LVL 7

Accepted Solution

by:
ramesh12 earned 250 total points
ID: 10864991
You can use RowFilter to find the row meeting your criteria like

dv.rowfilter "orderid=yourvalue and menuitemid=yourvalue1)

Now you can use your dataview
0
 

Author Comment

by:Tiare
ID: 10865355
Thats great, thanks.
Its funny how my mind was blank to go about it that way - even though I knew how.

Cheers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now