Home Forums WinForms controls Xceed Grid for WinForms ContextMenuStrip

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15542 |

    Is it posible to select row (and set to be current) on right click when ContextMenuStrip is set?
    How to determine on what element (header, row, cell, group) menu popup?

    Imported from legacy forums. Posted by Sasa (had 2904 views)

    User (Old forums)
    Member
    Post count: 23064

    Well, normally, to display a ContextMenu, you will handle to MouseDown event on the element on which you want to pop up a menu. In the same handler, simply set the CurrentRow (or CurrentCell) property and the SelectedRows collection to the row referenced by the sender.

    e.g.:
    <code>
    private void Form1_Load(object sender, System.EventArgs e)
    {
    foreach( Cell cell in dataRowTemplate1.Cells )
    {
    cell.MouseDown += new MouseEventHandler(cell_MouseDown);
    }
    }

    void cell_MouseDown( object sender, MouseEventArgs e )
    {
    Cell cell = sender as Cell;
    gridControl1.CurrentCell = cell;
    gridControl1.SelectedRows.Clear();
    gridControl1.SelectedRows.Add( cell.ParentRow );

    Point point = ( ( Cell )sender).ClientPointToGrid( new Point( e.X, e.Y ) );
    if( e.Button == MouseButtons.Right )
    {
    menu.Show( gridControl1, point );
    }
    }
    </code>

    Imported from legacy forums. Posted by André (had 323 views)

    User (Old forums)
    Member
    Post count: 23064

    It works but…

    1. I must set AllowCellNavigation to True
    2. Meni do not shows when click on group header, column header, empty space

    Imported from legacy forums. Posted by Sasa (had 260 views)

    User (Old forums)
    Member
    Post count: 23064

    You need to subscribe to the same event on any object on which you want to pop up the context menu, e.g. ColumnManagerRow.Cells, ColumnManagerRow, etc…

    Imported from legacy forums. Posted by André (had 3877 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.