Compartilhar via


DataGridCell.ColumnNumber Propriedade

Definição

Obtém ou define o número de uma coluna no controle DataGrid.

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

Valor da propriedade

Int32

O número da coluna.

Exemplos

O exemplo a seguir atribui a CurrentCell propriedade de um System.Windows.Forms.DataGrid a DataGridCell. O valor armazenado no DataTable é retornado especificando DataRow e DataColumn objetos por meio das propriedades e da RowNumber propriedade ColumnNumber .

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

Comentários

Você pode usar o ColumnNumber valor para especificar um DataColumn associado DataTable ao System.Windows.Forms.DataGrid controle.

Aplica-se a

Confira também