Context menu

3 posts, 0 answers
  1. Kim
    Kim avatar
    47 posts
    Member since:
    Jul 2013

    Posted 16 Oct 2013 Link to this post



    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. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3948 posts

    Posted 21 Oct 2013 Link to this post

    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 >>
  3. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 21 Oct 2013 Link to this post

    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 >>
Back to Top