none
Reading data from a cell in datagriview

    Question

  • Hey

    I use datagridview in visual basic 2005 and i have filled it up with data (read only) and now i would like to select a row and my program should read the number in the first column of that row.

    But how do i get it to read a value that can be stored in a variable?

    I cant seem to find anything about it.

    Sunday, April 09, 2006 9:16 PM

Answers

  • DataGridView class has a property called rows, which contains cells. You can access what you need from there.

    For example,

    DataGridView1.Rows(0).Cells(0).Value

    And in your case, when you need specifically the selected (current) row:

    DataGridView1.CurrentRow.Cells(0).Value

    Monday, April 10, 2006 8:56 AM

All replies

  • DataGridView class has a property called rows, which contains cells. You can access what you need from there.

    For example,

    DataGridView1.Rows(0).Cells(0).Value

    And in your case, when you need specifically the selected (current) row:

    DataGridView1.CurrentRow.Cells(0).Value

    Monday, April 10, 2006 8:56 AM
  • Thanx a lot! It works perfectly... 
    Monday, April 10, 2006 5:26 PM
  • String strOldStringValue = dataGridView.Rows[0].Cells[0].Value.ToString();

    dataGridView.Rows[0].Cells[0].Value = "New String Value";

     

    Please use square brakets - [ ] instead of ( )

    Wednesday, November 21, 2007 9:42 AM
  • This last example is only for C#.  In VB.Net you need to use the ( ) as mentioned.
    Wednesday, November 21, 2007 11:56 AM