How to get the cell position (Row& Column) from cursor?

Posted by: inexcon on 7 August 2017, 8:46 am EST

    • Post Options:
    • Link

    Posted 7 August 2017, 8:46 am EST

    Hi!

    I have a context menu with the right-click mouse button on C1FlexGrid. When user right-clicks on the grid, before showing the context menu, I would like to make the cell under the mouse to be the current one. (I am in MouseRightButtonDown event, so I can get the mouse position from there).

    How to get the current cell (Row & Column) from a cursor position?

    Thanks,

    Inexcon

  • Posted 7 August 2017, 8:46 am EST

    Hello Inexcon,

    You can use the HitTest method of the grid object and then with the help of HitTestInfo object, you can get a particular cell’s information in the grid.

    Here is what you can do :

    [csharp]private void c1flexgrid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)

    {

    if (c1flexgrid.HitTest(e.GetPosition(c1flexgrid)).CellType == C1.WPF.FlexGrid.CellType.Cell)

    {

    C1.WPF.FlexGrid.HitTestInfo hti = c1flexgrid.HitTest(e.GetPosition(c1flexgrid));

    MessageBox.Show("Row : " + hti.Row.ToString() + "Column : " + hti.Column.ToString());

    }

    }[/csharp]

    For more information about this method, please refer to the following documentation link :

    http://helpcentral.componentone.com/nethelp/c1flexgridwpf/#!XMLDocuments/FlexgridWPFRef/html/M_C1_WPF_FlexGrid_C1FlexGrid_HitTest_1_9ecf963a.htm

    Hope it helps.

    Regards,

    Reema

  • Posted 7 August 2017, 8:46 am EST

    Hi!

    I am not in WPF, I am in Silverlight. Does your solution works for Silverlight too?

    Inexcon

  • Posted 7 August 2017, 8:46 am EST

    Hello Inexcon,

    Apologies for the inconvenience caused.

    Yes, the same solution works in case of C1FlexGrid for Silverlight as well. Please refer to the below modified code and the respective documentation link :

    [csharp]

    private void c1Flexgrid1_MouseRightButtonDown_1(object sender, MouseButtonEventArgs e)

    {

    if (c1Flexgrid1.HitTest(e.GetPosition(c1Flexgrid1)).CellType == C1.Silverlight.FlexGrid.CellType.Cell)

    {

    C1.Silverlight.FlexGrid.HitTestInfo hti = c1Flexgrid1.HitTest(e.GetPosition(c1Flexgrid1));

    MessageBox.Show("Row : " + hti.Row.ToString() + "Column : " + hti.Column.ToString());

    }

    }

    [/csharp]

    http://helpcentral.componentone.com/nethelp/C1flexgridsilverlight/#!XMLDocuments/FlexSLref/html/M_C1_Silverlight_FlexGrid_C1FlexGrid_HitTest_1_9ecf963a.htm

    Hope it helps.

    Regards,

    Reema

  • Posted 10 February 2018, 7:54 am EST

    hey is there anything similar option for Datagrid too ?

  • Posted 25 June 2018, 1:24 am EST

    I have the same situation, but my grid is C1TrueDBGrid – and there is no HitTest method for that grid. How do I figure out what row/column the right mouse click menu selection was invoked on ?

    thank you

Need extra support?

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

Learn More

Forum Channels