ContextMenu for Flexgrid

Posted by: maximusdebois on 2 August 2021, 1:29 pm EST

    • Post Options:
    • Link

    Posted 2 August 2021, 1:29 pm EST

    I want to create a right click context menu for flexgrid rows. I tried something and it did work but anytime I select row programmatically it still reference the previous click row not the new selected row

    
    if (e.Button == MouseButtons.Right)
                {
                    var hti = usersGrid.HitTest(e.X, e.Y);
                    if (hti.Row != -1)
                    {
                        if (usersGrid.Rows[hti.Row].Selected == false)
                        {
                            foreach (Row row in usersGrid.Rows.Selected)
                            {
                                usersGrid.Rows[row.Index].Selected = false;
                            }
                            usersGrid.Rows[hti.Row].Selected = true;
                        }
                        int pos = usersGrid.HitTest(e.X, e.Y).Row;
                        MessageBox.Show(usersGrid.Row.ToString());
                        rc.Show(usersGrid, new Point(e.X, e.Y));
                    }
                }
    
    
  • Posted 3 August 2021, 1:02 am EST

    Hi,

    The Row property gets or sets the Row that contains the current cell. When you change selection programmatically, the current cell is not changed. You need to set the Row property explicitly when you are changing the selection.

    
    if (e.Button == MouseButtons.Right)
                {
                    var hti = c1FlexGrid1.HitTest(e.X, e.Y);
                    if (hti.Row != -1)
                    {
                        if (c1FlexGrid1.Rows[hti.Row].Selected == false)
                        {
                            foreach (Row row in c1FlexGrid1.Rows.Selected)
                            {
                                c1FlexGrid1.Rows[row.Index].Selected = false;
                            }
                            c1FlexGrid1.Rows[hti.Row].Selected = true;
                        }
                        c1FlexGrid1.Row = hti.Row;
    
                        MessageBox.Show(c1FlexGrid1.Row.ToString());
                    }
                }
    

    Regards

    Avnish

  • Posted 3 August 2021, 2:42 am EST

    Thank you so much it worked

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels