Results 1 to 4 of 4

Thread: [RESOLVED] Data Grid View (Show value for each cell in row)

Hybrid View

  1. #1

    Thread Starter
    Registered User
    Join Date
    Nov 2009
    Location
    New England
    Posts
    122

    Resolved [RESOLVED] Data Grid View (Show value for each cell in row)

    Hello again,

    I'm kind of stumped on how to get the data I want from a data grid view box.

    Simply Put, What I need to do is get every value from each cell in a row.

    So if row one is highlighted I need the Name, addy, and so on....from that row.

    Can someone lead me in the right direction with this.

    I have no idea how to code this one.

    As always, thanks to those who reply.

    Mike

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

    Re: Data Grid View (Show value for each cell in row)

    You can use nested For loops for the column index and row indexx to get each and every cell via the Item property of the grid. Alternatively, use a For Each loop to go through the Rows of the grid and another to go through the Cells of the row. Either way, once you have a cell, get its Value property to get the data it contains.

  3. #3
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Data Grid View (Show value for each cell in row)

    Code:
    For Each row As DataGridViewRow in YourDataGridView.SelectedRows
         MessageBox.Show(String.Format("First Cell: {0} Second Cell: {1}", row.Cells(0).Value, row.Cells(1).Value)
    Next
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  4. #4

    Thread Starter
    Registered User
    Join Date
    Nov 2009
    Location
    New England
    Posts
    122

    Thumbs up Re: Data Grid View (Show value for each cell in row)

    Thanks for replying,

    I ended up using jmc's way to get the data i needed. I appreciate your help with this issue. Thanks.

    Mike

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