DataGrid.Item[] 屬性

定義

取得或設定指定儲存格的值。

多載

名稱 Description
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

A DataGridCell 代表網格中的一個格子。

屬性值

該格子的值,類型為 Object

範例

以下程式碼範例透過宣告 DataGridCell 變數、設定其 RowNumberColumnNumber 值,然後先變更、再回傳該儲存格的值來設定並取得該儲存格的值。

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

包含該值的列的零為基礎的索引。

columnIndex
Int32

包含該值的欄位的零為基礎索引。

屬性值

該格子的值,類型為 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 到 指定列。

適用於