DataGridCell 構造体
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


DataGridCell を System.Windows.Forms.DataGrid コントロールの CurrentCell プロパティと組み合わせて使用すると、任意のセルの値を取得または設定できます。System.Windows.Forms.DataGrid コントロールの CurrentCell プロパティを DataGridCell に設定すると、DataGridCell で指定されているセルにフォーカスが移動します。

DataGridCell を System.Windows.Forms.DataGrid の CurrentCell に割り当て、選択したセルの列番号と行番号を返す例を次に示します。DataTable に格納されている値も、DataGridCell オブジェクトの RowNumber と ColumnNumber を使用して出力されます。
Private Sub PrintCellRowAndCol() Dim myCell As DataGridCell myCell = DataGrid1.CurrentCell Console.WriteLine(myCell.RowNumber) Console.WriteLine(myCell.ColumnNumber) ' Prints the value of the cell through the DataTable. Dim myTable As DataTable ' Assumes the DataGrid is bound to a DataTable. myTable = CType(DataGrid1.DataSource, DataTable) Console.WriteLine(myTable.Rows(myCell.RowNumber)(myCell.ColumnNumber)) End Sub
private void PrintCellRowAndCol() { DataGridCell myCell; myCell = DataGrid1.CurrentCell; Console.WriteLine(myCell.RowNumber); Console.WriteLine(myCell.ColumnNumber); // Prints the value of the cell through the DataTable. DataTable myTable; // Assumes the DataGrid is bound to a DataTable. myTable = (DataTable) DataGrid1.DataSource; Console.WriteLine(myTable.Rows[myCell.RowNumber] [myCell.ColumnNumber]); }
void PrintCellRowAndCol() { DataGridCell^ myCell; myCell = DataGrid1->CurrentCell; Console::WriteLine( myCell->RowNumber ); Console::WriteLine( myCell->ColumnNumber ); // Prints the value of the cell through the DataTable. DataTable^ myTable; // Assumes the DataGrid is bound to a DataTable. myTable = dynamic_cast<DataTable^>(DataGrid1->DataSource); Console::WriteLine( myTable->Rows[ myCell->RowNumber ][ myCell->ColumnNumber ] ); }
private void PrintCellRowAndCol() { DataGridCell myCell; myCell = dataGrid1.get_CurrentCell(); Console.WriteLine(myCell.get_RowNumber()); Console.WriteLine(myCell.get_ColumnNumber()); // Prints the value of the cell through the DataTable. DataTable myTable; // Assumes the DataGrid is bound to a DataTable. myTable = (DataTable)(dataGrid1.get_DataSource()); Console.WriteLine(myTable.get_Rows(). get_Item(myCell.get_RowNumber()). get_Item(myCell.get_ColumnNumber())); } //PrintCellRowAndCol


Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DataGridCell 構造体のページへのリンク