Right click should select cell and show menu

Posted by: datavalue on 8 September 2017, 6:22 am EST

  • Posted 8 September 2017, 6:22 am EST

    Using fpspread version 5.0.3505.2008:
    fpSpread does not select/activate the cell on right mouse click. If I want to show a context menu, I have to accept either:
    1. that the user must click the cell once with left mouse, then once again with right mouse click
    or
    2. that my actions are done for a cell which is not the active cell

    I tried on fpspread."mouse down right" to activate the right clicked cell by code, but then the context menu did not appear.
    Does somebody have a solution for the problem ?
    We just bought Spread studio 9, but didn't try it yet. Is the behavior of right mouse click different in that version ?
  • Marked as Answer

    Replied 8 September 2017, 6:22 am EST

    Hi,

    It should work to handle the CellClick event to check whether the right button was clicked in the cell and then set the active cell with SetActiveCell before showing your context menu.
    That should work just as well in v5 as in v9, and the code should be the same (these APIs are not changed between v5 and v9); here are help contexts for v9:
    http://sphelp.grapecity.com/WebHelp/SpreadNet9/WF/webframe.html#FarPoint.Win.Spread~FarPoint.Win.Spread.FpSpread~CellClick_EV.html
    http://sphelp.grapecity.com/WebHelp/SpreadNet9/WF/webframe.html#FarPoint.Win.Spread~FarPoint.Win.Spread.SheetView~SetActiveCell(Int32,Int32,Boolean).html

    Regards,
    -Sean
  • Replied 17 February 2020, 10:57 pm EST

    Hi,
    I want the cell to get selected with right mouse-click and display a context menu. Instead of doing a left click and then right click. I tried adding a condition to check whether the right button was clicked in the cell and then set the active cell with SetActiveCell. But it is just shifting the focus. cut, copy, paste and delete will not work.
  • Replied 18 February 2020, 10:17 am EST

    I would make the observation that this is a difference to the way Excel behaves.
  • Replied 18 February 2020, 3:39 pm EST

    Yeah exactly I want excel behavior. Is there a solution for this?
  • Replied 18 February 2020, 8:42 pm EST

    Hi Anud,

    The following code works just fine with the latest version Spread.Net 13. See attached video.
    private void FpSpread1_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
    {
    if(e.Button== MouseButtons.Right)
    {
    fpSpread1.ActiveSheet.SetActiveCell(e.Row, e.Column);
    }
    }

    Which Spread version are you using?

    Thanks
    Ruchir
    RightClickSelect_WinSpread.zip
  • Replied 19 February 2020, 12:09 am EST

    I have added the same code and on right click, cell is getting activated and showing context menu. But the copy option will not copy the contents of the cell selected with the right click instead it keeps the contents of the previous cell selected with the left click.
  • Replied 19 February 2020, 10:55 pm EST

    Hello,

    Now, I have modified the application shared previously to perform the Cut,Copy and Paste operations through context menu and as mentioned earlier, I cannot observe any issue. Running the attached application do you face the problem? Which Spread version are you using?

    Thanks,
    Ruchir
    RightClickSelect_WinSpreadContextMenu.zip
  • Replied 20 February 2020, 8:58 pm EST

    It was not working because in the existing code cut,copy,paste was being done considering Selection.Count>0 property. Now I have added the Row.Count>0 condition as well to make copy,cut,paste,delete work for the cell selected with right click. It works fine.
    Thank you.
  • Replied 23 February 2020, 3:50 pm EST

    Glad that the problem is now resolved and that you can proceed.

    ~Ruchir
  • Replied 24 February 2020, 3:46 am EST

    Hi,
    Is it possible to select multiple cells with right mouse click?
  • Replied 24 February 2020, 5:07 pm EST

    Hello,

    Yes. For instance, the following code selects cell range and multiple individual cells.
    private void FpSpread1_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
    {
    if(e.Button== MouseButtons.Right)
    {
    // select cell range
    fpSpread1.ActiveSheet.AddSelection(e.Row, e.Column, 3, 3);

    //select multiple individual cells
    fpSpread1.ActiveSheet.AddSelection(e.Row, e.Column, 1, 1);
    fpSpread1.ActiveSheet.AddSelection(e.Row + 1, e.Column + 1, 1, 1);
    fpSpread1.ActiveSheet.AddSelection(e.Row + 3, e.Column + 3, 1, 1);
    fpSpread1.ActiveSheet.AddSelection(e.Row + 5, e.Column + 5, 1, 1);
    }
    }
    Thanks,
    Ruchir
  • Replied 25 February 2020, 4:21 pm EST

    Thank you. It works fine.
    fpSpread1.ActiveSheet.AddSelection(e.Row, e.Column, 3, 3); will select 3 rows and 3 columns. But, what if the range is unknown?
  • Replied 25 February 2020, 4:38 pm EST

    Hello,

    >> But, what if the range is unknown?
    To select cell(s), one need to know its row/col indexes before invoking the AddSelection method. Even, if there is some condition (like select the fifth column from the current column etc) one can always calculate the indexes accordingly.
    Or is there something else you wanted to ask?

    Thanks,
    Ruchir
Need extra support?

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

Learn More

Forum Channels