DataGridCell.ColumnNumber 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 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
屬性值
資料行的編號。
範例
下列範例會將 CurrentCell 的 System.Windows.Forms.DataGrid 屬性指派給 DataGridCell 。 透過 和 ColumnNumber 屬性指定 DataRow 和 DataColumn 物件 RowNumber ,即可傳回儲存在 中的 DataTable 值。
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
備註
您可以使用 ColumnNumber 值,在 與 控制項相關聯的 System.Windows.Forms.DataGrid 中 DataTable 指定 DataColumn 。