Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
140
how to know which row the user has clicked on the grid for the context menu
posted

Hi All Hope you are all doing great.

 

I have created a context menu and have associated it with the grid. But I need selecte which row the user has clicked so that I can do manipulations to that row only.

Can anybody help me in doing this.

Thanks

 

  • 1590
    Suggested Answer
    posted

    I do not know is this solution a best one  but you can use this approach:

    1. Subscribe  on MouseClick event of a grid.

    grid_.MouseClick += new System.Windows.Forms.MouseEventHandler(this.OnGridMouseClick)

    2. In MouseClick handler check whether the pressed button is right one and if so

      determine what is the row you have clicked on:

    private void OnGridMouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    UIElement element = grid_.DisplayLayout.UIElement.ElementFromPoint(e.Location);
                    if (element != null)
                    {
                        UltraGridRow row = element.GetContext(typeof (UltraGridRow)) as UltraGridRow;              
                        if (row != null)
                        {
                         .... // save this row or do what you want.
                        }
                    }          

                }
           
        }

     

    Alex