Results 1 to 6 of 6

Thread: [RESOLVED] DataGridView searching

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    124

    Resolved [RESOLVED] DataGridView searching

    I've loaded a txt file in a DataGridView called DataGridView1.

    I've also got a search function which shows the row including that what you searched.

    When I search something it always is in a column called: "szName".
    The column in before "szName" is called "//dwID".

    How can I get the bit of text in column "//dwID" of the selected row in a TextBox (TextBox1)


    Thanks in Advance
    RATE MY POST

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: DataGridView searching

    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim matchRowdwID = (From dgvRow In DataGridView1.Rows _
    3.                 Let r = DirectCast(dgvRow, DataGridViewRow) _
    4.                 Where Not r.IsNewRow AndAlso r.Cells("szName").Value.ToString = TextBox1.Text _
    5.                 Select r.Cells("dwID").Value).ToArray
    6.  
    7.     If matchRowdwID.Count > 0 Then MsgBox(matchRowdwID.First.ToString)
    8.  
    9. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    124

    Re: DataGridView searching

    I'm using this code:

    Code:
        Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
            Dim matchRowdwID = (From dgvRow In DataGridView1.Rows Let r = DirectCast(dgvRow, DataGridViewRow) Where Not (r.IsNewRow AndAlso r.Cells("szName").Value.ToString = TextBox1.Text) Select r.Cells("//dwID").Value).ToArray
            If matchRowdwID.Count > 0 Then MsgBox(matchRowdwID.First.ToString)
        End Sub
    But it always shows the first match in //dwID
    Last edited by TooLongName; Jul 31st, 2010 at 08:52 AM.
    RATE MY POST

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: DataGridView searching

    Quote Originally Posted by TooLongName View Post
    But it always shows the first match in //dwID
    i tested it, so i know it works.
    do you mean there is more than one match returned from the query?

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: DataGridView searching

    "//dwID" is also not a valid name for a column

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    124

    Re: DataGridView searching

    I made a stupid mistake

    Code:
    Where Not r.IsNewRow AndAlso r.Cells("szName").Value.ToString = TextBox1.Text _
    The part where the searchterm is in isn't called TextBox1.Text but sSearchTerms...

    Thanks for the help paul
    RATE MY POST

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width