.NET Framework Class Library
DataGridCell.RowNumber Property

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

[Visual Basic]
Public Property RowNumber As Integer
[C#]
public int RowNumber {get; set;}
[C++]
public: __property int get_RowNumber();
public: __property void set_RowNumber(int);
[JScript]
public function get RowNumber() : int;
public function set RowNumber(int);

Property Value

The number of the row.

Remarks

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

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
Private Sub PrintCell(sender As Object, e As MouseEventArgs)
   Dim thisGrid As DataGrid = CType(sender, DataGrid)
   Dim myDataGridCell As DataGridCell = thisGrid.CurrentCell
   Dim bm As BindingManagerBase = _
   BindingContext (thisGrid.DataSource, thisGrid.DataMember)
   Dim drv As DataRowView = CType(bm.Current, DataRowView)
   Console.WriteLine(drv(myDataGridCell.ColumnNumber))
   Console.WriteLine(myDataGridCell.RowNumber)
End Sub


[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);
}


[C++] 
private:
void PrintCell(Object* sender, MouseEventArgs* /*e*/)
{
   DataGrid* thisGrid = dynamic_cast<DataGrid*> (sender);
   DataGridCell myDataGridCell = thisGrid->CurrentCell;
   BindingManagerBase* bm = BindingContext->Item[thisGrid->DataSource, thisGrid->DataMember];
   DataRowView* drv = dynamic_cast<DataRowView*> (bm->Current);
   Console::WriteLine(drv->Item[myDataGridCell.ColumnNumber]);
   Console::WriteLine(myDataGridCell.RowNumber);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataGridCell Structure | DataGridCell Members | System.Windows.Forms Namespace

Page view tracker