Right Mouse Button to select a row in C1TrueDBGrid

Posted by: ptobian on 16 January 2020, 6:10 am EST

    • Post Options:
    • Link

    Posted 16 January 2020, 6:10 am EST

    Hi!

    Is there a way to select a row with the right mouse button in C1TrueDBGrid?

  • Posted 17 January 2020, 5:52 am EST

    Hello,

    Please use the following lines of code:

    
     private void C1TrueDBGrid1_MouseClick(object sender, MouseEventArgs e)
            {
                if(e.Button == MouseButtons.Right)
                {
                    if(c1TrueDBGrid1.SelectedRows.IndexOf(c1TrueDBGrid1.RowContaining(e.Y))>=0)
                        c1TrueDBGrid1.SelectedRows.RemoveAt(c1TrueDBGrid1.SelectedRows.IndexOf(c1TrueDBGrid1.RowContaining(e.Y)));
                    else
                    c1TrueDBGrid1.SelectedRows.Add(c1TrueDBGrid1.RowContaining(e.Y));
                    
                }
            }
    
    

    Thanks,

    Mohit

  • Posted 20 January 2020, 4:10 am EST

    It works fine.

    Thank you

  • Posted 15 October 2021, 5:56 am EST

    If C1TrueDBGrid1 contains ContextMenuStrip, the C1TrueDBGrid1_MouseClick event will not be fired when right mouse button is clicked.

    Is there any way to solve this?

  • Posted 18 October 2021, 5:48 am EST

    Hello,

    The MouseClick event fires when you press and release the Mouse button but as the ContextMenu appears on MouseDown so it is preventing the execution of the MouseClick event.

    As a workaround you can use the same code in the MouseDown event:

      private void C1TrueDBGrid1_MouseDown(object sender, MouseEventArgs e)
           {
               if (e.Button == MouseButtons.Right)
               {
                   if (c1TrueDBGrid1.SelectedRows.IndexOf(c1TrueDBGrid1.RowContaining(e.Y)) >= 0)
                       c1TrueDBGrid1.SelectedRows.RemoveAt(c1TrueDBGrid1.SelectedRows.IndexOf(c1TrueDBGrid1.RowContaining(e.Y)));
                   else
                       c1TrueDBGrid1.SelectedRows.Add(c1TrueDBGrid1.RowContaining(e.Y));
    
               }
           }
    

    Regards,

    Prabhat Sharma.

  • Posted 18 October 2021, 9:47 am EST

    Thank you.

    I already solved it by manually showing ContextMenu on right mouse click, instead of assigning ContextMenu to the c1TrueDBGrid1.

  • Posted 19 October 2021, 6:32 am EST

    Hello,

    It is good to hear that you have resolved the issue at your end yourself.

    If you still need any help, please let us know.

    Regards,

    Prabhat Sharma.

Need extra support?

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

Learn More

Forum Channels