GrapeCity MultiRow Windows Forms Documentation
Context Menu

You can set the context menu (right-click menu) on the grid as well as on the cell editing control in the GcMultiRow control.

Grid Context Menu

Assign the context menu to be displayed on the grid with the GcMultiRow.ContextMenu property or the GcMultiRow.ContextMenuStrip property. If a menu has been assigned to both properties, the GcMultiRow.ContextMenu property has priority.

Using Code

This example sets the context menu.

[VB]

Dim menu As ContextMenuStrip = New ContextMenuStrip()
menu.Items.AddRange(New ToolStripItem() { _
    New ToolStripMenuItem("Test 1"), New ToolStripMenuItem("Test 2") })
GcMultiRow1.ContextMenuStrip = menu

[CS]

ContextMenuStrip menu = new ContextMenuStrip();
menu.Items.AddRange(new ToolStripItem[] { 
    new ToolStripMenuItem("Test 1"), new ToolStripMenuItem("Test 2") });
gcMultiRow1.ContextMenuStrip = menu;

By default, the context menu can be displayed by right clicking on it with the mouse, or by using the application key. The application key can be changed using the Shift + F10 key.

Mouse Cursor Object Type

Use the GcMultiRow.HitTest method to find the type of object being pointed to by the mouse. For example, you can have different actions when the mouse points to the header and when the mouse points to the cell.

Using Code

The following code changes the background color of a cell in a row when the mouse button is clicked on that cell.

[VB]

Imports GrapeCity.Win.MultiRow

Private Sub GcMultiRow1_MouseDown(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) Handles GcMultiRow1.MouseDown
    Dim gcMultiRow As GcMultiRow = TryCast(sender, GcMultiRow)
    Dim hitTestInfo As HitTestInfo = gcMultiRow.HitTest(e.X, e.Y)

    If hitTestInfo.Type = HitTestType.Row Then
        If hitTestInfo.CellIndex > -1 Then
            gcMultiRow(hitTestInfo.SectionIndex, hitTestInfo.CellIndex).Style.BackColor = Color.Azure
        End If
    End If
End Sub

[CS]

using GrapeCity.Win.MultiRow;

private void gcMultiRow1_MouseDown(object sender, MouseEventArgs e)
{
    GcMultiRow gcMultiRow = sender as GcMultiRow;
    HitTestInfo hitTestInfo = gcMultiRow.HitTest(e.X, e.Y);
    if (hitTestInfo.Type == HitTestType.Row)
    {
        if (hitTestInfo.CellIndex > -1)
        {
            gcMultiRow[hitTestInfo.SectionIndex, hitTestInfo.CellIndex].Style.BackColor = Color.Azure;
        }
    }
}

Row Context Menu

The context menu can be set at the row level as well.

Using Code

The following code assigns the context menu to the first row. This menu will be displayed on places other than the cells, or when the context menu has not been specified for the cells.

[VB]

Dim menu As ContextMenuStrip = New ContextMenuStrip()
menu.Items.AddRange(New ToolStripItem() { _
    New ToolStripMenuItem("Test 1"), New ToolStripMenuItem("Test 2") })
GcMultiRow1.Rows(0).ContextMenuStrip = menu

[CS]

ContextMenuStrip menu = new ContextMenuStrip();
menu.Items.AddRange(new ToolStripItem[] { 
    new ToolStripMenuItem("Test 1"), new ToolStripMenuItem("Test 2") });
gcMultiRow1.Rows[0].ContextMenuStrip = menu;

Cell Context Menu

The context menu can be specified for each cell by using the Cell.ContextMenuStrip property.

Using Code

The following code describes how to set the context menu for the first cell of the first row.

[VB]

Dim menu As ContextMenuStrip = New ContextMenuStrip()
menu.Items.AddRange(New ToolStripItem() { _
    New ToolStripMenuItem("Test 1"), New ToolStripMenuItem("Test 2") })
GcMultiRow1.Rows(0).Cells(0).ContextMenuStrip = menu

[CS]

ContextMenuStrip menu = new ContextMenuStrip();
menu.Items.AddRange(new ToolStripItem[] { 
    new ToolStripMenuItem("Test 1"), new ToolStripMenuItem("Test 2") });
gcMultiRow1.Rows[0].Cells[0].ContextMenuStrip = menu;

Cell Editing Control Context Menu

The context menu can be displayed while editing the cell if the cell editing control supports the context menu.

Using Code

This example illustrates the cell displaying the context menu while being edited.

[VB]

Imports GrapeCity.Win.MultiRow

Private Sub GcMultiRow1_EditingControlShowing(ByVal sender As System.Object, ByVal e As GrapeCity.Win.MultiRow.EditingControlShowingEventArgs) Handles GcMultiRow1.EditingControlShowing
    Dim textBoxEditingControl As TextBoxEditingControl = DirectCast(e.Control, TextBoxEditingControl)
    If textBoxEditingControl IsNot Nothing Then
        Dim menu As ContextMenuStrip = New ContextMenuStrip()
        menu.Items.AddRange(New ToolStripItem() { New ToolStripMenuItem("Test 1"), New ToolStripMenuItem("Test 2") })
        textBoxEditingControl.ContextMenuStrip = menu
    End If
End Sub

[CS]

using GrapeCity.Win.MultiRow;

private void gcMultiRow1_EditingControlShowing(
    object sender, EditingControlShowingEventArgs e)
{
    TextBoxEditingControl textBoxEditingControl = e.Control as TextBoxEditingControl;
    if (textBoxEditingControl != null)
    {
        ContextMenuStrip menu = new ContextMenuStrip();
        menu.Items.AddRange(new ToolStripItem[] {
            new ToolStripMenuItem("Test 1"), new ToolStripMenuItem("Test 2") });
        textBoxEditingControl.ContextMenuStrip = menu;
    }
}
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options