Results 1 to 3 of 3

Thread: Check if GridView Contains a value

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Check if GridView Contains a value

    I have a DataGridView that contains a few columns of data.
    Is there a way to check a column for a value before i add a new row, just to make sure i dont put dupes in it?

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

    Re: Check if GridView Contains a value

    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim found = From row As DataGridViewRow In DataGridView1.Rows.Cast(Of DataGridViewRow)() _
    3.                 Where row.Cells(1).Value.ToString = "value to find" _
    4.                 Select True
    5.     MsgBox(found.FirstOrDefault)
    6. End Sub

  3. #3
    New Member
    Join Date
    Oct 2010
    Posts
    7

    Re: Check if GridView Contains a value

    This is how I search value in a datagridview:

    For i = 0 To DataGridView1.RowCount - 1
    If DataGridView1.Rows(i).Cells("Column1").Value = "Value" Then
    MsgBox("x")
    End If
    Next

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