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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 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