PopupMenu on a selected cell of a DBGrid lazarus / 16-Databases ---------------------------------------------------------------------- dsyrios · 2019-01-07 17:41 Hi, I want to activate a PopupMenu over/nearby a selected cell on a DBGrid, using Right button click. I use the below code and it's ok about the proper column. But the PopupMenu is triggering all over the column, not only the selected cell. Maybe the OnMouseUp is not the right one procedure. Any helping tip? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;                                        Shift: TShiftState; X, Y: Integer);var  aCol, aRow : integer;begin if Button = mbRight then   begin     TDBGrid(Sender).MouseToCell(X,Y,aCol,aRow);     if (aCol=2)        { AND          aRow=???   <-- I need only the row of the selected cell      }       then begin          TDBGrid(Sender).PopupMenu.Popup;     end;   end;end; ---------------------------------------------------------------------- lucamar · 2019-01-07 18:03 The only helping tip is that you uncomment the "and aRow = "; as it is now it will pop-up everytime aCol = 2 ... which, of course, happens over all the column. But maybe I misunderstood the question? Also, if the popup menu is owned by the grid, doen't it pop-up any time you right-click anywhere inside it? ---------------------------------------------------------------------- dsyrios · 2019-01-07 19:35 @lukamar, thanks for the reply Maybe I wasn't clear enough. The PopupMenu is triggering all over the column with right click, I want to catch the SelectedCell TPoint(X,Y) coords NOT mouse coords so to do TDBGrid(Sender).PopupMenu.Popup(SelectedCell.X,SelectedCell.Y) ---------------------------------------------------------------------- lucamar · 2019-01-07 19:49 Let me test my understanding: your real problem is that you don't know the row number of the Selected cell, so you can't test for it in the OnMouseUp handler. Is that it? If so, let me check a couple things; I think I've seen something like this before ... ETA: got it! Not the most obvious thing in the world, but use Grid.SelectedRows; it should return just one bookmark unless there are more than one row selected. Incidentally ... why aren't you using OnCellClick? ---------------------------------------------------------------------- dsyrios · 2019-01-08 03:37 @lukamar, thanks for your attention. FYI, the below code maybe is somehow tricky, but now seems to works perfect for me. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i implementation...type  TDummyDBGrid=class(TDBGrid);...  procedure TForm1.DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;                                        Shift: TShiftState; X, Y: Integer);var  aCol, aRow, xRow : integer;begin xRow := TDummyDBGrid(TDBGrid(Sender)).Row;          { xrow  from DBGrid } TDBGrid(Sender).MouseToCell(X,Y,aCol,aRow);         { arow  from mouse } if (Button = mbRight)      AND (aCol=2)       AND (aRow=xRow)                                 then      TDBGrid(Sender).PopupMenu.Popup; {popup ONLY over the celected cell}end; ---------------------------------------------------------------------- lucamar · 2019-01-08 13:23 Yes, that would work too. But you don't need the double cast:   xRow := TDummyDBGrid(TDBGrid(Sender)).Row; you can just do:   xRow := TDummyDBGrid(Sender).Row; Also, although probably not needed it's always good manners to check the type before hard-casts like those: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if Sender is TDBGrid then begin    { Now you can safely do TDBGrid(Sender).whatever }  end;