Export (0) Print
Expand All

DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip Property

Gets or sets the shortcut menu for the row that raised the RowContextMenuStripNeeded event.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public ContextMenuStrip ContextMenuStrip { get; set; }
/** @property */
public ContextMenuStrip get_ContextMenuStrip ()

/** @property */
public void set_ContextMenuStrip (ContextMenuStrip value)

public function get ContextMenuStrip () : ContextMenuStrip

public function set ContextMenuStrip (value : ContextMenuStrip)

Not applicable.

Property Value

The ContextMenuStrip in use.

This property initially contains the value of the DataGridViewRow.ContextMenuStrip property if it has been set for a row.

The following code example handles the RowContextMenuStripNeeded event to provide a ContextMenuStrip based on the title of the employee. In this example, there are two shortcut menus, one for managers and one for all other employees. This example is part of a larger example available in the DataGridViewRowContextMenuStripNeededEventArgs class overview.

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;
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft