TFileListBox "right click" behavior lazarus / 31-LCL ---------------------------------------------------------------------- moit · 2010-06-25 10:00 So far I've tried this on Linux, OS X, and WinXP and see the same behavior on all three. I've got a TFileListBox that lists a bunch of files. I also have a context menu that pops up when you right click on the TFileFileBox. It works. But ... the behavior I am seeing is that a "right click" does not also select the item over which it has clicked. In other words, when I right click over something, the selected item does not change. I note that the "no-change on right-click" happens whether or not the TFileFileBox is associated with a TPopupMenu or not. What I would like to have happen is for a right click to also select the item over which it has been clicked -- and then pop up the context menu. Is there a magical incantation that will make this happen? -M ---------------------------------------------------------------------- theo · 2010-06-26 00:10 Just try. I did and found that the following works. Tested on Lazarus 0.9.29 r26057M FPC 2.4.0 i386-linux-gtk 2 (beta) Code: [Select]procedure TForm1.FileListBox1MouseDown(Sender:TObject;Button:TMouseButton;Shift:   TShiftState;X,Y:Integer); var item:integer; begin   item:=FileListBox1.ItemAtPos(Point(X,Y),true);   if item>-1 then FileListBox1.Selected[item]:=true; end; ---------------------------------------------------------------------- moit · 2010-06-26 02:42 Theo, your code on my 0.9.28.2-2 GTK gets closer. It selects the item under the right-click. But for some reason the routines fired off by the popup menu are seeing the 'old' selection. (For completeness, the popup menu brings up an 'Edit' item, the handler of which calls: Code: [Select]procedure TMainForm.OpenSelectedSourceFile(); begin   if self.sources_filelistbox.SelCount = 1 then     self.OpenInEditor(self.sources_filelistbox.FileName)   else     MessageDlg ('No file selected', 'You must first select a file from the Sources list.', mtError,                  [mbOk],0) end;where my TFileListBox is called sources_filelistbox) Thinking that what was happening was that the popup handling was taking place before the mouse down handling, I disabled the popup menu from the Object Inspector and tried popping it up manually: Code: [Select]procedure TMainForm.sources_filelistboxMouseDown(Sender: TObject;   Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var item:integer; begin   if Button = mbRight then   begin     item:=self.sources_filelistbox.ItemAtPos(Point(X,Y),true);     if item>-1 then     begin       self.sources_filelistbox.Selected[item]:=true;       sources_popupmenu.PopUp();     end;   end; end; This also makes the popup routines think they are working with the 'old' selection (?!) and introduces another oddity: Only every odd numbered right click brings up the popup. In other words, the first right click selects the item under the pointer and pops up the menu, the second only selects an item, the third selects the item and pops up the menu, the fourth only selects an item, etc. I also trued a small variation of the above that does NOT select the clicked item: Code: [Select]procedure TMainForm.sources_filelistboxMouseDown(Sender: TObject;   Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var item:integer; begin   if Button = mbRight then   begin     item:=self.sources_filelistbox.ItemAtPos(Point(X,Y),true);     if item>-1 then     begin       //self.sources_filelistbox.Selected[item]:=true;       sources_popupmenu.PopUp();     end;   end; end; This fixes the 'old selection' problem but not the 'every other right click' problem. I am confused but suspect I am missing something pretty basic here. ---------------------------------------------------------------------- theo · 2010-06-26 06:52 Pleas see if this is already reported in the bugtracker. If not, make a bug report with a minimal compilable project showing this bug. http://bugs.freepascal.org/view_all_bug_page.php?project_id=1