how to get the value of the cell in datagridview

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
 
D

Dr_Franz

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

or

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

or

DataGridView1.CurrentCell.Value
 
I

Ignacio Machin ( .NET/ C# MVP )

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top