DataGrid.Item[] Propiedad

Definición

Obtiene o establece el valor de una celda especificada.Gets or sets the value of a specified cell.

Sobrecargas

Item[DataGridCell]

Obtiene o establece el valor del objeto DataGridCell especificado.Gets or sets the value of a specified DataGridCell.

Item[Int32, Int32]

Obtiene o establece el valor de la celda ubicada en la fila y la columna especificadas.Gets or sets the value of the cell at the specified the row and column.

Item[DataGridCell]

Obtiene o establece el valor del objeto DataGridCell especificado.Gets or sets the value of a specified 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

Parámetros

cell
DataGridCell

DataGridCell que representa una celda de la cuadrícula.A DataGridCell that represents a cell in the grid.

Valor de propiedad

Object

El valor de la celda, cuyo tipo es Object.The value, typed as Object, of the cell.

Ejemplos

En el ejemplo de código siguiente se establece y se obtiene el valor de una celda declarando una DataGridCell variable, estableciendo sus valores RowNumber y ColumnNumber, cambiando primero y devolviendo el valor de la celda especificada.The following code example sets and gets the value of a cell by declaring a DataGridCell variable, setting its RowNumber and ColumnNumber values, then first changing, then returning, the value of the given cell.

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
    

Comentarios

Al establecer esta propiedad, se cambia la posición del DataView a la fila especificada.Setting this property changes the position of the DataView to the specified row.

Consulte también:

Item[Int32, Int32]

Obtiene o establece el valor de la celda ubicada en la fila y la columna especificadas.Gets or sets the value of the cell at the specified the row and column.

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

Parámetros

rowIndex
Int32

Índice de base cero de la fila que contiene el valor.The zero-based index of the row containing the value.

columnIndex
Int32

Índice de base cero de la columna que contiene el valor.The zero-based index of the column containing the value.

Valor de propiedad

Object

El valor de la celda, cuyo tipo es Object.The value, typed as Object, of the cell.

Excepciones

Mientras se obtiene o se establece el valor, rowIndex está fuera del intervalo.While getting or setting, the rowIndex is out of range.

Mientras se obtiene o se establece el valor, columnIndex está fuera del intervalo.While getting or setting, the columnIndex is out of range.

Ejemplos

En el ejemplo de código siguiente se imprime el valor contenido por la celda en la fila y el índice especificados.The following code example prints the value contained by the cell at the specified row and index.

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
    

Comentarios

Al establecer esta propiedad, se cambia la posición del DataView a la fila especificada.Setting this property changes the position of the DataView to the specified row.

Se aplica a