Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataGridCell.ColumnNumber Property

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public int ColumnNumber { get; set; }
/** @property */
public int get_ColumnNumber ()

/** @property */
public void set_ColumnNumber (int value)

public function get ColumnNumber () : int

public function set ColumnNumber (value : int)

Not applicable.

Property Value

The number of the column.

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

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.

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 void PrintCell(Object sender, MouseEventArgs e)
{
    DataGrid thisGrid = (DataGrid)(sender);
    DataGridCell myDataGridCell = thisGrid.get_CurrentCell();
    BindingManagerBase bm = get_BindingContext().
        get_Item(thisGrid.get_DataSource(), 
        thisGrid.get_DataMember());
    DataRowView drv = (DataRowView)(bm.get_Current());
    Console.WriteLine(drv.get_Item(myDataGridCell.get_ColumnNumber()));
    Console.WriteLine(myDataGridCell.get_RowNumber());
} //PrintCell

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show: