Right Click select row and ContextMenu (like Outlook)

Posted by: newsgroup_archive on 27 September 2017, 11:58 am EST

  • Posted 27 September 2017, 11:58 am EST



    Hello,



    I have a grid working in SelectionModeEnum.ListBox mode.



    I have a ContextMenu on the grid.



    When user RightMouse Clicks I want the grid to select the row and popup the menu. Is this possible?



    * Like the behaviour of Microsoft Excel and Outlook *



    The row select must be smart, if user has selected multiple rows using left mouse and ctrl/shift then they right click it should not change the row selection.

  • Posted 27 September 2017, 11:58 am EST





    Here is the solution:

    int row=c1FlexGrid1.MouseRow;

    int col=c1FlexGrid1.MouseCol;



    if (e.Button==MouseButtons.Right && row > c1FlexGrid1.Rows.Fixed)

    {

    // Test by selection mode

    if (c1FlexGrid1.SelectionMode == C1.Win.C1FlexGrid.SelectionModeEnum.ListBox)

    {

    // clicked on unselected row, so change selection.

    if (!c1FlexGrid1.Rows[row].Selected)

    {

    c1FlexGrid1.Row=row;

    }

    }

    else

    {

    if (!c1FlexGrid1.Selection.Contains(c1FlexGrid1.MouseRow,c1FlexGrid1.MouseCol))

    {

    c1FlexGrid1.Select(c1FlexGrid1.MouseRow, c1FlexGrid1.MouseCol);

    }



    }

    }





    “Kevin” wrote:

    >

    >Hello,

    >

    >I have a grid working in SelectionModeEnum.ListBox mode.

    >

    >I have a ContextMenu on the grid.

    >

    >When user RightMouse Clicks I want the grid to select the row and popup the menu. Is this possible?

    >

    >* Like the behaviour of Microsoft Excel and Outlook *

    >

    >The row select must be smart, if user has selected multiple rows using left mouse and ctrl/shift then they right click it should not change the row selection.



  • Posted 27 September 2017, 11:58 am EST





    The code below goes in the BeforeMouseDown event handler.



    “Kevin” wrote:

    >

    >

    >Here is the solution:

    > int row=c1FlexGrid1.MouseRow;

    > int col=c1FlexGrid1.MouseCol;

    >

    > if (e.Button==MouseButtons.Right && row > c1FlexGrid1.Rows.Fixed)

    > {

    > // Test by selection mode

    > if (c1FlexGrid1.SelectionMode == C1.Win.C1FlexGrid.SelectionModeEnum.ListBox)

    > {

    > // clicked on unselected row, so change selection.

    > if (!c1FlexGrid1.Rows[row].Selected)

    > {

    > c1FlexGrid1.Row=row;

    > }

    > }

    > else

    > {

    > if (!c1FlexGrid1.Selection.Contains(c1FlexGrid1.MouseRow,c1FlexGrid1.MouseCol))

    > {

    > c1FlexGrid1.Select(c1FlexGrid1.MouseRow, c1FlexGrid1.MouseCol);

    > }

    >

    > }

    > }

    >

    >

    >“Kevin” wrote:

    >>

    >>Hello,

    >>

    >>I have a grid working in SelectionModeEnum.ListBox mode.

    >>

    >>I have a ContextMenu on the grid.

    >>

    >>When user RightMouse Clicks I want the grid to select the row and popup the menu. Is this possible?

    >>

    >>* Like the behaviour of Microsoft Excel and Outlook *

    >>

    >>The row select must be smart, if user has selected multiple rows using left mouse and ctrl/shift then they right click it should not change the row selection.

    >



  • Posted 27 September 2017, 11:58 am EST



    Kevin,



    When I put the code “int row= c1FlexGrid1.MouseRow

    and int col=c1FlexGrid1.MouseCol” in my BeforeMouseDown event handler, The row, col is -1(0xffff) when i right click the mouse, even my mouse point is on the row of the grid, the left mouse click is working fine. What could be the problem?



    “Kevin” wrote:

    >

    >

    >The code below goes in the BeforeMouseDown event handler.

    >

    >“Kevin” wrote:

    >>

    >>

    >>Here is the solution:

    >> int row=c1FlexGrid1.MouseRow;

    >> int col=c1FlexGrid1.MouseCol;

    >>

    >> if (e.Button==MouseButtons.Right && row > c1FlexGrid1.Rows.Fixed)

    >> {

    >> // Test by selection mode

    >> if (c1FlexGrid1.SelectionMode == C1.Win.C1FlexGrid.SelectionModeEnum.ListBox)

    >> {

    >> // clicked on unselected row, so change selection.

    >> if (!c1FlexGrid1.Rows[row].Selected)

    >> {

    >> c1FlexGrid1.Row=row;

    >> }

    >> }

    >> else

    >> {

    >> if (!c1FlexGrid1.Selection.Contains(c1FlexGrid1.MouseRow,c1FlexGrid1.MouseCol))

    >> {

    >> c1FlexGrid1.Select(c1FlexGrid1.MouseRow, c1FlexGrid1.MouseCol);

    >> }

    >>

    >> }

    >> }

    >>

    >>

    >>“Kevin” wrote:

    >>>

    >>>Hello,

    >>>

    >>>I have a grid working in SelectionModeEnum.ListBox mode.

    >>>

    >>>I have a ContextMenu on the grid.

    >>>

    >>>When user RightMouse Clicks I want the grid to select the row and popup the menu. Is this possible?

    >>>

    >>>* Like the behaviour of Microsoft Excel and Outlook *

    >>>

    >>>The row select must be smart, if user has selected multiple rows using left mouse and ctrl/shift then they right click it should not change the row selection.

    >>

    >



  • Posted 1 March 2018, 11:15 pm EST

    Hi.,

    I’ve use your code above and it works fine but i have notice that when i try to click(right click) the first row. it wont select. only the second row and so on…

    can you please tell?

    Thanks…

Need extra support?

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

Learn More

Forum Channels