Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

5. Windows Forms Datagrid

5.33 How do I get the row and column of the current cell in my datagrid?


You can use the CurrentCell property of the DataGrid.

private void button1_Click(object sender, System.EventArgs e)
{
     intcolNum = dataGrid1.CurrentCell.ColumnNumber;
     int rowNum = dataGrid1.CurrentCell.RowNumber;
     object cellValue = dataGrid1[rowNum, colNum];
     string s = string.Format("row={0} col={1} value={2}", rowNum, colNum, cellValue);
     MessageBox.Show(s);
}