DataGrid.Item[] Proprietà

Definizione

Ottiene o imposta il valore di una cella specificata.

Overload

Nome Descrizione
Item[DataGridCell]

Ottiene o imposta il valore di un oggetto specificato DataGridCell.

Item[Int32, Int32]

Ottiene o imposta il valore della cella in corrispondenza della riga e della colonna specificata.

Item[DataGridCell]

Origine:
DataGrid.cs
Origine:
DataGrid.cs

Ottiene o imposta il valore di un oggetto specificato 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

Parametri

cell
DataGridCell

Oggetto DataGridCell che rappresenta una cella nella griglia.

Valore della proprietà

Valore, digitato come Object, della cella.

Esempio

L'esempio di codice seguente imposta e ottiene il valore di una cella dichiarando una DataGridCell variabile, impostandone i RowNumber valori e ColumnNumber , quindi modificando prima, quindi restituendo, il valore della cella specificata.

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

Commenti

Se si imposta questa proprietà, la posizione dell'oggetto DataView viene modificata nella riga specificata.

Vedi anche

Si applica a

Item[Int32, Int32]

Origine:
DataGrid.cs
Origine:
DataGrid.cs

Ottiene o imposta il valore della cella in corrispondenza della riga e della colonna specificata.

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

Parametri

rowIndex
Int32

Indice in base zero della riga contenente il valore.

columnIndex
Int32

Indice in base zero della colonna contenente il valore.

Valore della proprietà

Valore, digitato come Object, della cella.

Eccezioni

Durante il recupero o l'impostazione, l'oggetto non è compreso nell'intervallo rowIndex .

Durante il recupero o l'impostazione, l'oggetto non è compreso nell'intervallo columnIndex .

Esempio

Nell'esempio di codice seguente viene stampato il valore contenuto dalla cella in corrispondenza della riga e dell'indice specificati.

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

Commenti

Se si imposta questa proprietà, la posizione dell'oggetto DataView viene modificata nella riga specificata.

Si applica a