DataGrid.Item[] 속성

정의

지정된 셀의 값을 가져오거나 설정합니다.

오버로드

Item[DataGridCell]

지정된 DataGridCell의 값을 가져오거나 설정합니다.

Item[Int32, Int32]

지정된 행 및 열에 있는 셀의 값을 가져오거나 설정합니다.

Item[DataGridCell]

지정된 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

Object로 형식이 지정된 셀의 값입니다.

예제

다음 코드 예제에서는 변수를 선언하고DataGridCell, 변수 및 ColumnNumber 값을 설정한 RowNumber 다음, 먼저 지정된 셀의 값을 변경한 다음 반환하여 셀의 값을 설정하고 가져옵니다.

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]

지정된 행 및 열에 있는 셀의 값을 가져오거나 설정합니다.

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

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 위치가 변경됩니다.

적용 대상