Results 1 to 2 of 2

Thread: Datagrid help

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    1

    Datagrid help

    hello, this is what i am trying to do:

    if textbox1.text = **** then
    MsgBox("Correct serial", MsgBoxStyle.DefaultButton1)
    form2.show
    me.close
    else
    MsgBox("Incorrect serial", MsgBoxStyle.DefaultButton1)


    For the **** part i wish to do this.
    if the text in textbox1 one is equal to ANY cell in the column named serial# in datagridview1.

    Thanks in advanced.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Datagrid help

    There are a few different ways to do this, but let's stick to the basics to begin with. When you want to do the same thing multiple times with different data, your first thought should be a loop. If you say out loud what you want to do, that will pretty much tell you what type of loop to use. In this case, you want to compare the contents of a TextBox with the contents of the cell in a particular column for each row. Obviously, you want to use a For Each loop that loops through the Rows of the grid. Inside the loop, get the Value for the appropriate cell and compare that to the Text of the TextBox.

    As for the messages, I'd suggest that you use a Boolean flag to indicate whether a match was found or not. Initialise it to False and, if a match is found in the loop, set the flag to True and exit. At the end of the loop, test that flag and display the appropriate message.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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