This is a migrated thread and some comments may be shown as answers.

Context menu

2 Answers 185 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kim
Top achievements
Rank 1
Kim asked on 16 Oct 2013, 11:19 PM


Hi, how do I display the grid's context menu if there are no rows in the grid? I want to right click in the white space and show the context menu.

Thanks,

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Oct 2013, 10:57 AM
Hello Kim,

Thank you for contacting Telerik Support.

In order to achieve your goal, please have a look at the following code snippet:
ContextMenu contextMenu = new ContextMenu();
 
public Form1()
{
    InitializeComponent();
 
    this.radGridView1.MouseDown += radGridView1_MouseDown;
    contextMenu.MenuItems.Add(new MenuItem("Item 1"));
    contextMenu.MenuItems.Add(new MenuItem("Item 2"));
}
 
private void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    RadGridView grid = sender as RadGridView;
    if (grid != null && e.Button == System.Windows.Forms.MouseButtons.Right)
    {
        grid.ContextMenu = contextMenu;
        grid.ContextMenu.Show(grid, e.Location);
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Stefan
Telerik team
answered on 21 Oct 2013, 10:58 AM
Hello Kim,

Thank you for contacting Telerik Support.

In order to achieve your goal, please have a look at the following code snippet:
ContextMenu contextMenu = new ContextMenu();
 
public Form1()
{
    InitializeComponent();
 
    this.radGridView1.MouseDown += radGridView1_MouseDown;
    contextMenu.MenuItems.Add(new MenuItem("Item 1"));
    contextMenu.MenuItems.Add(new MenuItem("Item 2"));
}
 
private void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    RadGridView grid = sender as RadGridView;
    if (grid != null && e.Button == System.Windows.Forms.MouseButtons.Right)
    {
        grid.ContextMenu = contextMenu;
        grid.ContextMenu.Show(grid, e.Location);
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Kim
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Stefan
Telerik team
Share this question
or