Topic: Grid Custom Popup Menu, Right Click and Selection Problem
Hello,
I have been testing out this software and so far it is brilliant!
However, I have encountered a problem that I am unsure how to solve and would like to know if there is any solution, perhaps I am doing something wrong? (I am new to Pascal).
In summary: I think when you right-click on a grid row, the SelectedCount gets updated after the actions of OnMouseUp/OnMouseDown which means one can't utilize the count for changing items in the menu.
A little bit in depth: I have a grid with some rows and a custom popup menu. The menu is defined as a separate procedure and gets to run every time there is either OnChange and OnMouseUp/OnMouseDown event.
Something like (simplified):
PopupMenuItem := TMenuItem.Create (PopupMenu);
PopupMenuItem .Caption := 'Always Visible';
PopupMenuItem .OnClick := @proc1;
PopupMenu.Items.Add(PopupMenuItem);
if (form.grid.SelectedCount > 0) and (form.grid.RowCount > 0) then
begin
PopupMenuItem := TMenuItem.Create (PopupMenu);
PopupMenuItem .Caption := 'Remove Selected';
PopupMenuItem .OnClick := @proc2;
PopupMenu.Items.Add(PopupMenuItem);
end;
if form.grid.RowCount > 0 then
begin
PopupMenuItem := TMenuItem.Create (PopupMenu);
PopupMenuItem .Caption := 'Remove All';
PopupMenuItem .OnClick := @proc3;
PopupMenu.Items.Add(PopupMenuItem );
The problem: upon first load of the GUI when nothing is selected in the grid, if you right-click on one of the rows, the menu that shows will not show "Remove Selected", only upon a second mouse click it will show it. As I explained, with my tests I think the SelectedCount is updated after the actions of actions of OnMouseUp/OnMouseDown.
I also tried the OnClick/OnCellClick events but from what I tested they only get triggered upon a left-click and not right-click.
Is there anyway to solve this? perhaps a better approach to all of this "custom popup menu" since one must also consider keyboard input etc.?
Any input would be much appreciate - thank you in advance!
SandBird