This project is read-only.

how to identify which cell is selected for contextmenu?

Jul 16, 2009 at 10:00 PM

I try to use a context menu for each cell, but I do not know how to identify

which cell is selected when I clik the cell and the corresponding contextmenu is shown.

the basic code is used by my is shown as follows, which is from the document:

anyone can give me one hint how to know which cell is clicked or selected.

thank you!


//Define a controller with a ContextMenu
public class PopupMenu : SourceGrid.Cells.Controllers.ControllerBase
ContextMenu menu = new ContextMenu();
public PopupMenu()
        menu.MenuItems.Add("Menu 1", new EventHandler(Menu1_Click));
menu.MenuItems.Add("Menu 2", new EventHandler(Menu2_Click));

public override void OnMouseUp(SourceGrid.CellContext sender, MouseEventArgs e)
base.OnMouseUp (sender, e);

if (e.Button == MouseButtons.Right)
menu.Show(sender.Grid, new Point(e.X, e.Y));

    private void Menu1_Click(object sender, EventArgs e)
        //TODO Your code here
    private void Menu2_Click(object sender, EventArgs e)
        //TODO Your code here

Jul 17, 2009 at 7:25 AM

sender.Position doesn't contain the right cell information ?

If you want the focused cell and not the cell where you "RightClicked", I think you can use sender.Grid.Selection.ActivePosition.

Jul 22, 2009 at 7:11 AM

It should be sender.Position, as jray noted

Sep 6, 2010 at 1:38 PM

nope the sender is MenuItem instead of Cell, therefore there is no sender.Position.
You have to save the position information in MouseUp as shown here The example was given

Sep 10, 2010 at 7:49 AM


But warning: by default, a right click on a cell doesn't select the cell where the click is made

Sep 28, 2010 at 12:12 PM

I am trying to make a right click to select the row. I happen to be using popup menu so I did this in order to achieve it:

sender.Grid.Selection.SelectRow(sender.Position.Row, true);

This is inside the OnMouseUp event, and it works.

However can anyone confirm that this is the best approach? Thanks a lot.