Recent

Author Topic: The text editor's system context menu is replaced by the parent popupMenu.  (Read 3992 times)

Mr.Paul

  • New Member
  • *
  • Posts: 29
  • 一次编写,到处编译
In a TsringGrid, the default is not popupmenu, when a cell into the edit state, the editing area will respond to the right mouse button, pop-up system menu, including in Windows10: Undo / Copy / Paste / Select All / Close IME and so on . I like this system menu.

However, when I bind a custom popupmenu to this Grid, the cell edit pop-up menu will also be changed to the Grid popupmenu, which is not what I want!   I hope that the original cell system context menu can be preserved.

Some people and I raised the same question, he uploaded the Chinese picture online, according to him, the problem appeared in Delphi 7.0, but to Delphi XE, the problem disappeared. Look here https://zhidao.baidu.com/question/494639215.html

An already solved topic may be related to my problem, which was fixed in 1.4, but I did not understand how to solve my problem at Lazarus 1.8RC4. http://forum.lazarus.freepascal.org/index.php?topic=26797.0

I hope I can clearly describe this problem, please help, thank you!
« Last Edit: January 10, 2018, 02:51:51 pm by Mr.Paul »

jamie

  • Hero Member
  • *****
  • Posts: 6995
Create the custom Popup menu as you need but don't assign it to the stringGrid...

 In the grid, use the OnSelectEditor Event and test first to see if the current editor is
the TstringCellEditor class., if so then check to see if it is in EDIT mode, if so simply exit which
will allow the standard Context menu to show, if it is not in EDIT mode, then call the PopUp Menu
you created and force it to show..

  Basically what I am saying is while in the OnSelectEditor you can text for the editor that is in use
and then make some choices as to how you want the Context menu to show. Simply do not assign the
custom Menu you created to the StringGrid or don't have it do auto popup.. You want to manually popup the
 menu you created when the StringCellEditor is not in EDIT MODE.
 
  I suppose this could be a bug? not sure.. but there is always a work around  :D
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6995
here is a simple way to get around it..

procedure TForm1.StringGrid1ContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
begin
  Handled := True;
  MousePos := StringGrid1.ClientToScreen(MousePos);
  StringGrid1.PopupMenu.PopUp(MousePos.X,MousePos.Y);
end;
             
You need to make sure you don't have the custom popup set to auto.
When the StringCellEdit is in EDIT mode, this event does not get called, instead the Windows Menu will popup
           
The only true wisdom is knowing you know nothing

Mr.Paul

  • New Member
  • *
  • Posts: 29
  • 一次编写,到处编译
I succeeded !   with your method, thank you very much!  :)
The attachment is an example project.
And, one sentence seems useless:
Code: Pascal  [Select][+][-]
  1. // Handled: = True;
no understand, thinking……

jamie

  • Hero Member
  • *****
  • Posts: 6995
Its possible you don't need the "handled := True"? But you could try to enable the
AutoPopUp using the Handled := True,  To see if it cancels the auto-popup.

 That is what the Handle Boolean is for, to instruct the control your code has handled the PopUp so it
shouldn't attempt to show it. But I am not sure if it works, you'll need to test..

 Glad your problem is solved for the time being.  ;)


The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018