DataGridViewRowContextMenuStripNeededEventArgs.RowIndex 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得要求捷徑功能表之資料列的索引。
public:
property int RowIndex { int get(); };
public int RowIndex { get; }
member this.RowIndex : int
Public ReadOnly Property RowIndex As Integer
屬性值
要求捷徑功能表之資料列的以零起始的索引。
範例
下列程式碼範例會處理 事件, RowContextMenuStripNeeded 以根據員工的職稱提供 ContextMenuStrip 。 在此範例中,有兩個快顯功能表,一個用於經理,另一個用於所有其他員工。 此範例是類別概觀中較大範例的 DataGridViewRowContextMenuStripNeededEventArgs 一部分。
void dataGridView1_RowContextMenuStripNeeded(object sender,
DataGridViewRowContextMenuStripNeededEventArgs e)
{
DataGridViewRow dataGridViewRow1 = dataGridView1.Rows[e.RowIndex];
toolStripMenuItem1.Enabled = true;
// Show the appropriate ContextMenuStrip based on the employees title.
if ((dataGridViewRow1.Cells["Title"].Value.ToString() ==
"Sales Manager") ||
(dataGridViewRow1.Cells["Title"].Value.ToString() ==
"Vice President, Sales"))
{
e.ContextMenuStrip = managerMenuStrip;
}
else
{
e.ContextMenuStrip = employeeMenuStrip;
}
contextMenuRowIndex = e.RowIndex;
}
Public Sub dataGridView1_RowContextMenuStripNeeded( _
ByVal sender As Object, _
ByVal e As DataGridViewRowContextMenuStripNeededEventArgs) _
Handles dataGridView1.RowContextMenuStripNeeded
Dim dataGridViewRow1 As DataGridViewRow = _
dataGridView1.Rows(e.RowIndex)
toolStripMenuItem1.Enabled = True
' Show the appropriate ContextMenuStrip based on the employees title.
If dataGridViewRow1.Cells("Title").Value.ToString() = _
"Sales Manager" OrElse _
dataGridViewRow1.Cells("Title").Value.ToString() = _
"Vice President, Sales" Then
e.ContextMenuStrip = managerMenuStrip
Else
e.ContextMenuStrip = employeeMenuStrip
End If
contextMenuRowIndex = e.RowIndex
End Sub
備註
使用這個屬性來擷取資料列的其他資訊。