Export (0) Print
Expand All

DataGridViewCell.ContextMenuStrip Property

Gets or sets the shortcut menu associated with the cell.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public virtual ContextMenuStrip ContextMenuStrip { get; set; }

Property Value

Type: System.Windows.Forms.ContextMenuStrip
The ContextMenuStrip associated with the cell.

This property indicates the shortcut menu that is typically displayed when the user right-clicks the cell.

When the DataGridView control DataSource property is set or its VirtualMode property is true, getting the value of the ContextMenuStrip property raises the CellContextMenuStripNeeded event of the control and returns the value of the DataGridViewCellContextMenuStripNeededEventArgs.ContextMenuStrip property as specified in the event handler. If there are no handlers for the event, getting the value of the ContextMenuStrip property returns the previously specified value or its default value of null.

Handling the CellContextMenuStripNeeded event is primarily useful when working with large amounts of data to avoid performance penalties when setting the cell ContextMenuStrip value for multiple cells. For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.

Changing this property raises the CellContextMenuStripChanged event on the owning DataGridView, if one exists.

You can also specify shortcut menus for individual rows rather than individual cells by setting the row ContextMenuStrip property or handling the DataGridView control's RowContextMenuStripNeeded event. The cell ContextMenuStrip property setting overrides the row ContextMenuStrip property setting, and the CellContextMenuStripNeeded event overrides both the RowContextMenuStripNeeded event and the row ContextMenuStrip property setting. You can specify null for a cell shortcut menu, however, to prevent a row shortcut menu from being overridden.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft