DataGridCell.ColumnNumber Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the number of a column in the DataGrid control.
public:
property int ColumnNumber { int get(); void set(int value); };
public int ColumnNumber { get; set; }
member this.ColumnNumber : int with get, set
Public Property ColumnNumber As Integer
Property Value
The number of the column.
Examples
The following example assigns the CurrentCell property of a System.Windows.Forms.DataGrid to a DataGridCell. The value stored in the DataTable is returned by specifying DataRow and DataColumn objects through the RowNumber and ColumnNumber properties.
void PrintCell( Object^ sender, MouseEventArgs^ /*e*/ )
{
DataGrid^ thisGrid = dynamic_cast<DataGrid^>(sender);
DataGridCell myDataGridCell = thisGrid->CurrentCell;
BindingManagerBase^ bm = BindingContext[ thisGrid->DataSource,thisGrid->DataMember ];
DataRowView^ drv = dynamic_cast<DataRowView^>(bm->Current);
Console::WriteLine( drv[ myDataGridCell.ColumnNumber ] );
Console::WriteLine( myDataGridCell.RowNumber );
}
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);
}
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
Remarks
You can use the ColumnNumber value to specify a DataColumn in the DataTable associated with the System.Windows.Forms.DataGrid control.