語言

DataGridView.Item[] 屬性

定義

提供索引器,用以取得或設定位於指定列與欄交點的儲存格。

多載

名稱 Description
Item[Int32, Int32]

提供索引器,以取得或設定位於具有指定索引之數據行和數據列交集的儲存格。

Item[String, Int32]

提供索引器,以取得或設定位於數據列交集的儲存格,以及具有指定名稱的數據行。

Item[Int32, Int32]

來源:
DataGridView.cs
來源:
DataGridView.cs
來源:
DataGridView.cs
來源:
DataGridView.cs
來源:
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]

來源:
DataGridView.cs
來源:
DataGridView.cs
來源:
DataGridView.cs
來源:
DataGridView.cs
來源:
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集合存取儲存格的替代方案。

另請參閱

適用於