DataGridCell.RowNumber Property

Definition

Gets or sets the number of a row in the DataGrid control.

C#
public int RowNumber { get; set; }

Property Value

The number of the row.

Examples

The following example assigns the CurrentCell property of a System.Windows.Forms.DataGrid to a DataGridCell and returns the value stored in the DataTable object's RowNumber and ColumnNumber properties.

C#
private void PrintCell(object sender, MouseEventArgs e)
{
   DataGrid thisGrid = (DataGrid) sender;
   DataGridCell myDataGridCell = thisGrid.CurrentCell;
   BindingManagerBase bm = BindingContext[thisGrid.DataSource, thisGrid.DataMember];
   DataRowView drv = (DataRowView) bm.Current;
   Console.WriteLine(drv [myDataGridCell.ColumnNumber]);
   Console.WriteLine(myDataGridCell.RowNumber);
}

Remarks

You can use the RowNumber value to specify a DataRow in the DataTable associated with the System.Windows.Forms.DataGrid control.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 10