Problem with contextmenu from the example

Feb 1, 2010 at 12:42 PM

Hi 

I have a contextmenu (right click) all the code is from the examples, i did create a new project copy the code from the GridSample. In the sample when u rightclick this code is run:

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

But i cant reach the grid from Menu1_Click.  i Tried with sender.Position, but when i type in sender. nothing really comes up.  I need to manipulate the cells in the grid from Menu1_Click. 

I did a search in the forum and found this one: 
http://sourcegrid.codeplex.com/Thread/View.aspx?ThreadId=62680

But that solution dosent work for me.

Using SourceGrid 4.20
VS2005 C#

 

Feb 2, 2010 at 7:35 AM

Hello!

Yes, the sender is MenuItem. My workaround on this situation:

public class PopupMenu : SourceGrid.Cells.Controllers.ControllerBase
{
    ContextMenu menu = new ContextMenu();
    private SourceGrid.CellContext popupContext;

    public PopupMenu()
    {
        popupContext = SourceGrid.CellContext.Empty;
        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)
        {
            popupContext = sender;
            menu.Show(sender.Grid, new Point(e.X, e.Y));
        }
    }

    private void Menu1_Click(object sender, EventArgs e)
    {
        SourceGrid.Cells.ICellVirtual iCellVirtual = this.popupContext.Grid.GetCell(this.popupContext.Position);
    }
    private void Menu2_Click(object sender, EventArgs e)
    {
        //TODO Your code here
    }
}