次の方法で共有


DataGridCell 構造体

グリッド内のセルを識別します。

この型のすべてのメンバの一覧については、DataGridCell メンバ を参照してください。

System.Object
   System.ValueType
      System.Windows.Forms.DataGridCell

Public Structure DataGridCell
[C#]
public struct DataGridCell
[C++]
public __value struct DataGridCell

[JScript] JScript では、.NET Framework の構造体を利用することができます。ただし、独自に定義することはできません。

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

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

使用例

[Visual Basic, C#, C++] DataGridCellSystem.Windows.Forms.DataGridCurrentCell に割り当て、選択したセルの列番号と行番号を返す例を次に示します。 DataTable に格納されている値も、 DataGridCell オブジェクトの RowNumberColumnNumber を使用して出力されます。

 
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


[C#] 
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]);
}


[C++] 
private:
   void PrintCellRowAndCol() {
      DataGridCell __gc *myCell;
      myCell = __box(DataGrid1->CurrentCell);
      Console::WriteLine(myCell->RowNumber);
      Console::WriteLine(myCell->ColumnNumber);
      // Prints the value of the cell through the DataTable.
      DataTable __gc *myTable;
      // Assumes the DataGrid is bound to a DataTable.
      myTable = dynamic_cast<DataTable *>(DataGrid1->DataSource);
      Console::WriteLine(myTable->Rows->Item[myCell->RowNumber]->Item[myCell->ColumnNumber]);
   };

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Windows.Forms

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)

参照

DataGridCell メンバ | System.Windows.Forms 名前空間 | CurrentCell | DataColumn | DataGrid | DataRow | ColumnNumber | RowNumber