指定した行および列にあるセルの値を取得または設定します。
[C#] C# では、このプロパティは DataGrid クラスのインデクサになります。
Overloads Public Default Property Item( _
ByVal rowIndex As Integer, _ ByVal columnIndex As Integer _) As Object
[C#]
public object this[introwIndex,intcolumnIndex] {get; set;}
[C++]
public: __property Object* get_Item(introwIndex,intcolumnIndex);public: __property void set_Item(introwIndex,intcolumnIndex, Object*);
[JScript]
returnValue = DataGridObject.Item(rowIndex, columnIndex);DataGridObject.Item(rowIndex, columnIndex) = returnValue;またはreturnValue = DataGridObject(rowIndex, columnIndex);DataGridObject(rowIndex, columnIndex) = returnValue;
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- rowIndex
値を格納している行の、0 から始まるインデックス番号。 - columnIndex
値を格納している列の、0 から始まるインデックス番号。
パラメータ [Visual Basic, C#, C++]
- rowIndex
値を格納している行の、0 から始まるインデックス番号。 - columnIndex
値を格納している列の、0 から始まるインデックス番号。
プロパティ値
object 型のセルの値。
例外
例外の種類 | 条件 |
---|---|
ArgumentOutOfRangeException | 取得または設定しているときに、 rowIndex が範囲外です。
取得または設定しているときに、 columnIndex が範囲外です。 |
解説
このプロパティを設定すると、 DataView の位置が指定した行に変更されます。
使用例
[Visual Basic, C#, C++] 指定した行およびインデックスにあるセルが格納している値を出力する例を次に示します。
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
[C#]
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]);
}
}
}
[C++]
private:
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->get_Item(iRow,iCol));
}
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
DataGrid クラス | DataGrid メンバ | System.Windows.Forms 名前空間 | DataGrid.Item オーバーロードの一覧