Solved

Datagrid - Select row based on row value

Posted on 2004-10-27
1,507 Views
Last Modified: 2010-05-18
Hey!

Say i have a datagird with data like

Dave :  $10.00
Bill   :   $20.00
Steve :  $50.00

How do i select the row with Dave??

Cheers!

Dave
0
Question by:flavo
    6 Comments
     
    LVL 1

    Accepted Solution

    by:
    something like:

                Dim wibble As New DataGrid
                Dim table As DataTable = CType(wibble.DataMember, DataTable)
                For Each row As DataRow In table.Rows
                    If CType(row.Item("Name"), String).Trim.Equals("Dave") Then
                        'do something - select the row here....
                    End If
                Next

    hth,

    james
    0
     
    LVL 28

    Assisted Solution

    by:iboutchkine
    and  here is how to select row

    DataGrid1.Select(DataGrid1.CurrentRowIndex)
    0
     
    LVL 8

    Assisted Solution

    by:wguerram
    Try this:

     ' Get the Currency Manager by using the BindingContext of the DataGrid
            Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource, DataGrid1.DataMember), CurrencyManager)

            ' Retrieve the default DataView of the DataGrid
            Dim dv As DataView = CType(cm.List, DataView)

            Dim drv() As DataRowView
            'Sort the DataView coumn to search
            dv.Sort = "CustomerID"
            'Search the row
            drv = dv.FindRows(TextBox1.Text)

            'If found position the cursor in the row found
            If drv.Length > 0 Then
                cm.Position = cm.List.IndexOf(drv(0))
            End If
    0
     
    LVL 34

    Author Comment

    by:flavo
    Thanks guys.
    0
     
    LVL 8

    Expert Comment

    by:wguerram
    You're welcome.
    0
     
    LVL 1

    Expert Comment

    by:jameskearney
    no probs
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    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…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    This video discusses moving either the default database or any database to a new volume.

    845 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

    10 Experts available now in Live!

    Get 1:1 Help Now