Manually display context menu

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

    Posted 26 Jul 2013 Link to this post

    I have read you can use this to manually invoke the context menu.

    this
    .radGridView1.ContextMenuManager.ShowContextMenu(radGridView1.CurrentCell)
    )

    However, what if you want to display the menu and there are no rows? What do i pass as a parm?

    Thanks,

    Kim  
  2. Kim
    Kim avatar
    47 posts
    Member since:
    Jul 2013

    Posted 26 Jul 2013 Link to this post

    HI,

    I found a way around this.
  3. Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 31 Jul 2013 Link to this post

    Hi Kim,

    Thank you for writing.

    It is good to know that you have found a solution, but keep in mind that if you are displaying the context menu with this expression in the mousedown event, both the default and yours context menus will be shown.

    I hope this information helps. Should you have any other questions, I will be glad to assist you.

    Regards,
    Dimitar
    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 >>
  4. Kim
    Kim avatar
    47 posts
    Member since:
    Jul 2013

    Posted 31 Jul 2013 Link to this post

    Fyi, I use this code to determine if the user clicked on a row or not. This prevents both menus from popping up.

    private void Grid_MouseClick(object sender, MouseEventArgs e)
    {
    if (e.Button == System.Windows.Forms.MouseButtons.Right)
    {
     if (gridViewDocuments.ElementTree.GetElementAtPoint(e.Location) is GridCellElement)
                        {
    //grid will show default context menu
                            return;
                        }

    //here I can show my custom menu as the grid context menu will not popup.
    }
    }
  5. Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 02 Aug 2013 Link to this post

    Hello Kim,

    Thank you for writing back.

    There is no need to show the default menu, just show your custom menu like this:
    if (e.Button == System.Windows.Forms.MouseButtons.Right)
    {
        if (!(radGridView1.ElementTree.GetElementAtPoint(e.Location) is GridCellElement))
        {
            // Show your custom menu here
        }
    }

    I also have prepared a small sample project to illustrate the code in action

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Regards,
    Dimitar
    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