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
370 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET Application Installation with sqlserver 8 67
Need help with a query 3 49
"lblTime is not declared" 3 64
Whice version VisualStudio for new Dev Laptop? 10 40
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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