DataGrid.Item[] プロパティ

定義

指定したセルの値を取得または設定します。

オーバーロード

名前 説明
Item[DataGridCell]

指定した DataGridCellの値を取得または設定します。

Item[Int32, Int32]

指定した行と列のセルの値を取得または設定します。

Item[DataGridCell]

ソース:
DataGrid.cs
ソース:
DataGrid.cs

指定した DataGridCellの値を取得または設定します。

public:
 property System::Object ^ default[System::Windows::Forms::DataGridCell] { System::Object ^ get(System::Windows::Forms::DataGridCell cell); void set(System::Windows::Forms::DataGridCell cell, System::Object ^ value); };
public object this[System.Windows.Forms.DataGridCell cell] { get; set; }
member this.Item(System.Windows.Forms.DataGridCell) : obj with get, set
Default Public Property Item(cell As DataGridCell) As Object

パラメーター

cell
DataGridCell

グリッド内のセルを表す DataGridCell

プロパティ値

セルの Objectとして型指定された値。

次のコード例では、 DataGridCell 変数を宣言し、その RowNumber 値と ColumnNumber 値を設定し、最初に指定されたセルの値を変更してから返すことで、セルの値を設定して取得します。

void SetCellValue( DataGrid^ myGrid )
{
   DataGridCell myCell;
   
   // Use an arbitrary cell.
   myCell.RowNumber = 1;
   myCell.ColumnNumber = 1;
   
   // Change the cell's value using the CurrentCell.
   myGrid[ myCell ] = "New Value";
}

void GetCellValue( DataGrid^ myGrid )
{
   DataGridCell myCell;
   
   // Use and arbitrary cell.
   myCell.RowNumber = 1;
   myCell.ColumnNumber = 1;
   Console::WriteLine( myGrid[ myCell ] );
}
private void SetCellValue(DataGrid myGrid){
   DataGridCell myCell = new DataGridCell();
   // Use an arbitrary cell.
   myCell.RowNumber = 1;
   myCell.ColumnNumber = 1;
   // Change the cell's value using the CurrentCell.
   myGrid[myCell]="New Value";
}
 
private void GetCellValue(DataGrid myGrid){
   DataGridCell myCell = new DataGridCell();
   // Use and arbitrary cell.
   myCell.RowNumber = 1;
   myCell.ColumnNumber = 1;
   Console.WriteLine(myGrid[myCell]);
}
Private Sub SetCellValue(ByVal myGrid As DataGrid)
   Dim myCell As New DataGridCell()
   ' Use an arbitrary cell.
   myCell.RowNumber = 1
   myCell.ColumnNumber = 1
   ' Change the cell's value using the CurrentCell.
   myGrid(myCell)= "New Value"
End Sub
 
Private Sub GetCellValue(ByVal myGrid As DataGrid)
   Dim myCell As New DataGridCell()
   ' Use an arbitrary cell.
   myCell.RowNumber = 1
   myCell.ColumnNumber = 1
   Console.WriteLine(myGrid(myCell))
End Sub

注釈

このプロパティを設定すると、 DataView の位置が指定した行に変更されます。

こちらもご覧ください

適用対象

Item[Int32, Int32]

ソース:
DataGrid.cs
ソース:
DataGrid.cs

指定した行と列のセルの値を取得または設定します。

public:
 property System::Object ^ default[int, int] { System::Object ^ get(int rowIndex, int columnIndex); void set(int rowIndex, int columnIndex, System::Object ^ value); };
public object this[int rowIndex, int columnIndex] { get; set; }
member this.Item(int * int) : obj with get, set
Default Public Property Item(rowIndex As Integer, columnIndex As Integer) As Object

パラメーター

rowIndex
Int32

値を含む行の 0 から始まるインデックス。

columnIndex
Int32

値を含む列の 0 から始まるインデックス。

プロパティ値

セルの Objectとして型指定された値。

例外

取得または設定中に、 rowIndex が範囲外です。

取得または設定中に、 columnIndex が範囲外です。

次のコード例では、指定した行とインデックスのセルに含まれる値を出力します。

void PrintCellValues( DataGrid^ myGrid )
{
   int iRow;
   int iCol;
   DataTable^ myTable;
   
   // Assumes the DataGrid is bound to a DataTable.
   myTable = dynamic_cast<DataTable^>(dataGrid1->DataSource);
   for ( iRow = 0; iRow < myTable->Rows->Count; iRow++ )
   {
      for ( iCol = 0; iCol < myTable->Columns->Count; iCol++ )
      {
         Console::WriteLine( myGrid[iRow, iCol] );

      }

   }
}
private void PrintCellValues(DataGrid myGrid){
    int iRow;
    int iCol;
    DataTable myTable;
    // Assumes the DataGrid is bound to a DataTable.
    myTable = (DataTable) dataGrid1.DataSource;
    for(iRow = 0;iRow < myTable.Rows.Count ;iRow++) {
       for(iCol = 0;iCol < myTable.Columns.Count ;iCol++) {
          Console.WriteLine(myGrid[iRow, iCol]);
       }
    }
 }
Private Sub PrintCells(ByVal myGrid As DataGrid)
    Dim iRow As Integer
    Dim iCol As Integer
    Dim myTable As DataTable
    ' Assumes the DataGrid is bound to a DataTable.
    myTable = CType(DataGrid1.DataSource, DataTable)
    For iRow = 0 To myTable.Rows.Count - 1
       For iCol = 0 To myTable.Columns.Count - 1
          Console.WriteLine(myGrid(iRow, iCol))
       Next iCol
    Next iRow
 End Sub

注釈

このプロパティを設定すると、 DataView の位置が指定した行に変更されます。

適用対象