DataGridView.Item[] 属性

定义

提供一个索引器来获取或设置位于指定行和列的交集处的单元格。

重载

名称 说明
Item[Int32, Int32]

提供一个索引器,用于获取或设置位于具有指定索引的列和行的交集处的单元格。

Item[String, Int32]

提供一个索引器来获取或设置位于具有指定索引的行的交集处的单元格,以及具有指定名称的列。

Item[Int32, Int32]

Source:
DataGridView.cs
Source:
DataGridView.cs
Source:
DataGridView.cs
Source:
DataGridView.cs
Source:
DataGridView.cs

提供一个索引器,用于获取或设置位于具有指定索引的列和行的交集处的单元格。

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; }
[<System.ComponentModel.Browsable(false)>]
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

包含单元格的列的索引。

rowIndex
Int32

包含单元格的行的索引。

属性值

位于 DataGridViewCell 指定位置。

属性

例外

columnIndex 小于 0 或大于控件中的列数减 1。

-或-

rowIndex 小于 0 或大于控件中的行数减 1。

示例

下面的代码示例演示如何使用此索引器。

// 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)

注解

此索引器是通过集合集合访问单元格 CellsRows 替代方法。

另请参阅

适用于

Item[String, Int32]

Source:
DataGridView.cs
Source:
DataGridView.cs
Source:
DataGridView.cs
Source:
DataGridView.cs
Source:
DataGridView.cs

提供一个索引器来获取或设置位于具有指定索引的行的交集处的单元格,以及具有指定名称的列。

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; }
[<System.ComponentModel.Browsable(false)>]
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

包含单元格的列的名称。

rowIndex
Int32

包含单元格的行的索引。

属性值

位于 DataGridViewCell 指定位置。

属性

示例

下面的代码示例演示如何使用此索引器。

// 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)

注解

此索引器是通过集合集合访问单元格 CellsRows 替代方法。

另请参阅

适用于