DataGridView.Item[String, Int32] 属性

定义

提供索引器以获取或设置位于指定行和指定列交叉点处的单元格。Provides an indexer to get or set the cell located at the intersection of the specified row and column.

重载

Item[Int32, Int32]

提供索引器以获取或设置位于具有指定索引的列和行的交叉点处的单元格。Provides an indexer to get or set the cell located at the intersection of the column and row with the specified indexes.

Item[String, Int32]

提供索引器以获取或设置位于具有指定索引的行和具有指定名称的列的交叉点处的单元格。Provides an indexer to get or set the cell located at the intersection of the row with the specified index and the column with the specified name.

Item[Int32, Int32]

提供索引器以获取或设置位于具有指定索引的列和行的交叉点处的单元格。Provides an indexer to get or set the cell located at the intersection of the column and row with the specified indexes.

public:
 property System::Windows::Forms::DataGridViewCell ^ default[int, int] { System::Windows::Forms::DataGridViewCell ^ get(int columnIndex, int rowIndex); void set(int columnIndex, int rowIndex, System::Windows::Forms::DataGridViewCell ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell this[int columnIndex, int rowIndex] { get; set; }
member this.Item(int * int) : System.Windows.Forms.DataGridViewCell with get, set
Default Public Property Item(columnIndex As Integer, rowIndex As Integer) As DataGridViewCell

参数

columnIndex
Int32

包含单元格的列的索引。The index of the column containing the cell.

rowIndex
Int32

包含该单元格的行的索引。The index of the row containing the cell.

属性值

位于指定位置的 DataGridViewCellThe DataGridViewCell at the specified location.

属性

异常

columnIndex 小于 0 或大于控件中的列数减 1。columnIndex is less than 0 or greater than the number of columns in the control minus 1.

- 或 --or- rowIndex 小于 0 或大于控件中的行数减 1。rowIndex is less than 0 or greater than the number of rows in the control minus 1.

示例

下面的代码示例演示如何使用此索引器。The following code example demonstrates the use of this indexer.

// Retrieve the cell value for the cell at column 3, row 7.
String testValue1 = (String)dataGridView1[3, 7].Value;

// Retrieve the cell value for the cell in the Name column at row 4.
String testValue2 = (String)dataGridView1["Name", 4].Value;
' Retrieve the cell value for the cell at column 3, row 7.
Dim testValue1 As String = CStr(dataGridView1(3, 7).Value)

' Retrieve the cell value for the cell in the Name column at row 4.
Dim testValue2 As String = CStr(dataGridView1("Name", 4).Value)

注解

此索引器是通过 @no__t 集合的 Cells 集合访问单元的替代方法。This indexer is an alternative to accessing cells through the Cells collection of the Rows collection.

另请参阅

Item[String, Int32]

提供索引器以获取或设置位于具有指定索引的行和具有指定名称的列的交叉点处的单元格。Provides an indexer to get or set the cell located at the intersection of the row with the specified index and the column with the specified name.

public:
 property System::Windows::Forms::DataGridViewCell ^ default[System::String ^, int] { System::Windows::Forms::DataGridViewCell ^ get(System::String ^ columnName, int rowIndex); void set(System::String ^ columnName, int rowIndex, System::Windows::Forms::DataGridViewCell ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell this[string columnName, int rowIndex] { get; set; }
member this.Item(string * int) : System.Windows.Forms.DataGridViewCell with get, set
Default Public Property Item(columnName As String, rowIndex As Integer) As DataGridViewCell

参数

columnName
String

包含该单元格的列的名称。The name of the column containing the cell.

rowIndex
Int32

包含该单元格的行的索引。The index of the row containing the cell.

属性值

位于指定位置的 DataGridViewCellThe DataGridViewCell at the specified location.

属性

示例

下面的代码示例演示如何使用此索引器。The following code example demonstrates the use of this indexer.

// Retrieve the cell value for the cell at column 3, row 7.
String testValue1 = (String)dataGridView1[3, 7].Value;

// Retrieve the cell value for the cell in the Name column at row 4.
String testValue2 = (String)dataGridView1["Name", 4].Value;
' Retrieve the cell value for the cell at column 3, row 7.
Dim testValue1 As String = CStr(dataGridView1(3, 7).Value)

' Retrieve the cell value for the cell in the Name column at row 4.
Dim testValue2 As String = CStr(dataGridView1("Name", 4).Value)

注解

此索引器是通过 @no__t 集合的 Cells 集合访问单元的替代方法。This indexer is an alternative to accessing cells through the Cells collection of the Rows collection.

另请参阅

适用于