Home Forums WinForms controls Xceed Grid for WinForms Context Menu for Xceed Grid

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

    I want to display context menu on the right click of Data rows only. But My context menu shows on right click everywhere including scroll bars, row selector pane. Is there a better way to do it?
    Thanks

    Imported from legacy forums. Posted by xUser (had 3952 views)

    User (Old forums)
    Member
    Post count: 23064

    I assume you’re using the ContextMenu property of the gridcontrol. The problem with this property is that no events are fired when the context menu should be displayed. If you want more control over this, you’ll have to implement your own handler.
    <code>
    myGridControl.MouseDown += new MouseEventHandler(myGridControl_MouseDown);

    private void myGridControl_MouseDown(object sender, MouseEventArgs e)
    {
    if (e.Button == MouseButtons.Right)
    {
    Xceed.Grid.DataCell cell = myGridControl.GetVisualGridElementAtPoint(e.X, e.Y) as Xceed.Grid.DataCell;
    if (cell != null)
    {
    Xceed.Grid.DataRow row = cell.ParentRow as Xceed.Grid.DataRow;
    myContextMenu.Show(myGridControl, new System.Drawing.Point(e.X, e.Y));
    }
    }
    }</code>

    Imported from legacy forums. Posted by Tommy (had 397 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the quick response. But My grid doesn’t response to any mouse events. This is how I did:
    myGridControl.BeginInit();
    myGridControl.SetDataBinding(ds, “TEST”);
    myGridControl.MouseDown += new MouseEventHandler(myGridControl_MouseDown);

    foreach(Xceed.Grid.DataCell cell in myGridControl.DataRowTemplate.Cells)
    {cell.DoubleClick += new EventHandler(CellDoubleClick);}
    myGridControl.EndInit();

    Imported from legacy forums. Posted by xUser (had 419 views)

    User (Old forums)
    Member
    Post count: 23064

    Its now working when I added context menu to cell’s mouse down event as shown below but now Context Menu doesn’t display at the correct location.The X and Y coord’s are based off the cell, not the cell’s location in the grid. How do I get the cell’s location?

    grdReport.BeginInit();
    grdReport.SetDataBinding(ds, “REPORT”);
    foreach(Xceed.Grid.DataCell cell in grdReport.DataRowTemplate.Cells)
    {cell.DoubleClick += new EventHandler(CellDoubleClick);
    cell.MouseDown += new MouseEventHandler(Cell_MouseDown);}
    grdReport.EndInit();

    private void Col_MouseDown(object sender, MouseEventArgs e )
    {
    if (e.Button == MouseButtons.Right )
    {
    contextMenu1.Show(grdReport, new System.Drawing.Point(e.X, e.Y));
    }

    }

    Imported from legacy forums. Posted by xUser (had 1111 views)

    User (Old forums)
    Member
    Post count: 23064

    got it to work. I am posting it so that others can use it.

    private void Col_MouseDown(object sender, MouseEventArgs e )
    {
    if (e.Button == MouseButtons.Right )
    {
    contextMenu1.Show(grdReport,(sender as Xceed.Grid.Cell).ClientPointToGrid(new Point(e.X, e.Y)));
    }

    }

    Imported from legacy forums. Posted by xUser (had 4752 views)

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