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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

13 Experts available now in Live!

Get 1:1 Help Now