how to get the value of the cell in datagridview

  • Thread starter Thread starter Claudia Fong
  • Start date Start date
C

Claudia Fong

Hi

I have a datagrid with 12 columns and various rows...

what I want to do is to get the value of each cell, e.g. column3 row1,
column4 row1, etc..

I was using dataGridView1.Rows[dataGridView1.RowIndex].Cells but I got
an error of System.Windows.Forms.DataGridView' does not contain a
definition for 'RowIndex'

Can someone tell me how can I get the value?


Cheers!

Claudi
 
DataGridView1.Rows[DataGridView1.CurrentRow.Index].Cells[0].Value

or

DataGridView1[0, DataGridView1.CurrentRow.Index].Value

or

DataGridView1.CurrentCell.Value
 
Hi

I have a datagrid with 12 columns and various rows...

what I want to do is to get the value of each cell, e.g. column3 row1,
column4 row1, etc..

I was using dataGridView1.Rows[dataGridView1.RowIndex].Cells but I got
an error of System.Windows.Forms.DataGridView' does not contain a
definition for 'RowIndex'      

Can someone tell me how can I get the value?

Cheers!

    Claudi

*** Sent via Developersdexhttp://www.developersdex.com***

RowIndex is a property of the Cell, not of the grid.
You can use DataGridView.Rows to get the collection of the rows, then
use the Cells property of each row:

DataGridView1.Rows[ X ].Cells[ Y ]
returns the column Y of the row X
 
Back
Top