GrapeCity MultiRow Windows Forms Documentation
ContextMenuStrip Property (Cell)
Example 


Gets or sets the shortcut menu associated with the cell.
Syntax
<SRCategoryAttribute("Behavior")>
<SRDescriptionAttribute("Indicates the shortcut menu to display when the user right-clicks the cell.")>
<DefaultValueAttribute()>
<BrowsableAttribute(False)>
Public Overridable Property ContextMenuStrip As ContextMenuStrip
Dim instance As Cell
Dim value As ContextMenuStrip
 
instance.ContextMenuStrip = value
 
value = instance.ContextMenuStrip
[SRCategory("Behavior")]
[SRDescription("Indicates the shortcut menu to display when the user right-clicks the cell.")]
[DefaultValue()]
[Browsable(false)]
public virtual ContextMenuStrip ContextMenuStrip {get; set;}

Property Value

A System.Windows.Forms.ContextMenuStrip value that represents the shortcut menu associated with the cell. The default is a null reference (Nothing in Visual Basic).
Remarks

This property indicates the shortcut menu that is typically displayed when the user right-clicks the cell. Changing this property raises the GcMultiRow.CellContextMenuStripChanged event.

You can handle the GcMultiRow's GcMultiRow.CellContextMenuStripNeeded event when the GcMultiRow.DataSource or GcMultiRow.VirtualMode property is set for the control. This is useful when working with large amounts of data to avoid performance penalties when setting the cell's ContextMenuStrip value for multiple cells.

You can also specify shortcut menus for individual sections rather than individual cells by setting the section's Section.ContextMenuStrip property or by handling the GcMultiRow control's GcMultiRow.SectionContextMenuStripNeeded event. Setting the cell's ContextMenuStrip property overrides the section's Section.ContextMenuStrip property setting, and the GcMultiRow.CellContextMenuStripNeeded event overrides both the SectionContextMenuStripNeeded event and the section's ContextMenuStrip property setting. You can specify a a null reference (Nothing in Visual Basic) for a cell's shortcut menu; however, to prevent a section's shortcut menu from being overridden.

Example
The following code example shows how to hide the clicked row when the ContextMenuStrip pops up on the RowHeaderCell. You can use cut, copy, and paste with the ContextMenuStrip menu.
private void Form1_Load(object sender, EventArgs e)
        {
            Template template1 = Template.CreateGridTemplate(10, 80, 21, 1000, AutoGenerateGridTemplateStyles.RowHeaderAutoNumber);
            
            template1.Row.ContextMenuStrip = sectionMenuStrip;

            foreach (Cell item in template1.Row.Cells)
            {
                if (!(item is RowHeaderCell))
                {
                    item.ContextMenuStrip = cellMenu;
                }
            }

            gcMultiRow1.Template = template1;
            gcMultiRow1.RowCount = 20;
            gcMultiRow1.CellMouseDown += new EventHandler<CellMouseEventArgs>(gcMultiRow1_CellMouseDown);
        }
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim template1 As Template = Template.CreateGridTemplate(10, 80, 21, 1000, AutoGenerateGridTemplateStyles.RowHeaderAutoNumber)

        template1.Row.ContextMenuStrip = sectionMenuStrip

        For Each item As Cell In template1.Row.Cells
            If Not (TypeOf item Is RowHeaderCell) Then
                item.ContextMenuStrip = cellMenu
            End If
        Next

        gcMultiRow1.Template = template1
        gcMultiRow1.RowCount = 20
    End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Cell Class
Cell Members
ContextMenuStrip Property
ContextMenuStrip Property
CellContextMenuStripChanged Event
CellContextMenuStripNeeded Event
SectionContextMenuStripNeeded Event

 

 


Copyright © GrapeCity, inc. All rights reserved.