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.

C#
public int ColumnNumber { get; set; }

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.

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 ColumnNumber value to specify a DataColumn 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

See also