DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip 属性            
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置引发 RowContextMenuStripNeeded 事件的行的快捷菜单。
public:
 property System::Windows::Forms::ContextMenuStrip ^ ContextMenuStrip { System::Windows::Forms::ContextMenuStrip ^ get(); void set(System::Windows::Forms::ContextMenuStrip ^ value); };
	public System.Windows.Forms.ContextMenuStrip ContextMenuStrip { get; set; }
	public System.Windows.Forms.ContextMenuStrip? ContextMenuStrip { get; set; }
	member this.ContextMenuStrip : System.Windows.Forms.ContextMenuStrip with get, set
	Public Property ContextMenuStrip As ContextMenuStrip
	属性值
正在使用的 ContextMenuStrip。
示例
下面的代码示例处理 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
	注解
此属性最初包含属性的值( DataGridViewRow.ContextMenuStrip 如果已为行设置)。