Datagrid - selectedrow ?

Jelmer

Regular
Joined
Jan 11, 2006
Messages
96
How can i get the rownumber from a Datagridview.
In some other programming languages you can use e selectedindex ore something.

What i need:

I select a row, and i like to get something out of it..

dataGridView1.Rows[1].Cells[0].Value.ToString()

Row = 1 at that code..
That 1 should be the rownumber of the selected row...

How ?
 
If I need to get the first column value from a datagrid I use the following

Visual Basic:
DataGrid1(DataGrid1.CurrentRowIndex, 0).ToString()

So in your case if would most probably look like this:

Visual Basic:
dataGridView1(dataGridView1.currentRowindex, 0).ToString()

Hope this helps :D
 
SonicBoomAu said:
If I need to get the first column value from a datagrid I use the following

Visual Basic:
DataGrid1(DataGrid1.CurrentRowIndex, 0).ToString()

So in your case if would most probably look like this:

Visual Basic:
dataGridView1(dataGridView1.currentRowindex, 0).ToString()

Hope this helps :D

Sorry i forgot to say that i use C#

dataGridView1.currentRowindex doesnt exist in C# ?
 
In C# ist like this.. i found it just out :)

dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString()
 
Jelmer said:
Sorry i forgot to say that i use C#

dataGridView1.currentRowindex doesnt exist in C# ?

CurrentRowIndex is a property of a DataGrid, however you are using a DataGridView which presumably has different properties. I can't help however as I don't appear to have this control, assumably its a VS 2005 control.
 
Cags said:
CurrentRowIndex is a property of a DataGrid, however you are using a DataGridView which presumably has different properties. I can't help however as I don't appear to have this control, assumably its a VS 2005 control.
you shouldnt be getting your data out of the grid, you should be getting it out of the bound data.

use a binding source. BindingSource.Current is the underlying object displayed in the selected row of the grid.
 
Back
Top