Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I determine the row and column of the current cell in a DataGrid?

You can use the CurrentCell property of the DataGrid.

private void button1_Click(object sender, System.EventArgs e)
{
  int colNum = 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);
}

Contributed from George Shepherd's Windows Forms FAQ



Page view counter