String grid dbl click question lazarus / 31-LCL ---------------------------------------------------------------------- jbmckim · 2018-06-13 22:14 I'm puzzled by the SG dbl click event behavior. I'm trying to dbl click on a column header, check to see if I'm in a given column and then do some work based on being in the given column.  This almost works except that when the column header is the first thing "clicked," the MyStringGrid.SelectedColumn.Index is given as zero.  Clicking anywhere else on the form first and MyStringGrid.SelectedColumn.Index is = to the appropriate column.  I'd like to have the column index be relevant from the first click. Thanks. P.S. Puzzling but irrelevant, I tried to dummy up a SG to post here but it behaves differently.  (Possibly based on SG Options but that's not really my problem here.) ---------------------------------------------------------------------- wp · 2018-06-13 22:37 This is working for me: Use the event OnHeaderClick which gives you the clicked column index as a parameter. Store the index and use it in the OnDblClick. 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 type  TForm1 = class(TForm)    StringGrid1: TStringGrid;    procedure StringGrid1DblClick(Sender: TObject);    procedure StringGrid1HeaderClick(Sender: TObject; IsColumn: Boolean;      Index: Integer);  private    FColClicked: Integer;  end;//...procedure TForm1.StringGrid1HeaderClick(Sender: TObject; IsColumn: Boolean;  Index: Integer);begin  if IsColumn then FColClicked := Index;end; procedure TForm1.StringGrid1DblClick(Sender: TObject);begin  ShowMessage('Double click in column ' + IntToStr(FColClicked));end; ---------------------------------------------------------------------- jbmckim · 2018-06-15 00:00 This is almost right, however a problem still remains. If I click anywhere on the grid and THEN click the header,  OnHeaderClick is executed.  If however, my first click is on the column header, OnHeaderClick is not executed.  (I verified focus by posting a break in OnMouseDown.) OnMouseDown does not have the row/column coordinates available the first time through (i.e. as above) so I can't use that. The grid is on a form with a TAChart and another stringgrid. ---------------------------------------------------------------------- wp · 2018-06-15 07:13 I cannot confirm that OnHeaderClick does not fire always. But anyway, maybe this is what you need: the grid has this method: 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 MouseToCell(X,Y: Integer; var ACol,ARow: Longint); ---------------------------------------------------------------------- fred · 2018-06-15 07:30 I just converted an old Delphi 5 program to Lazarus and used in DblClick: 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   P := grid.ScreenToClient(Mouse.CursorPos);  grid.MouseToCell(P.X, P.Y, myCol, myRow); ---------------------------------------------------------------------- jbmckim · 2018-06-15 17:42 Those things didn't work but it did get me to thinking. OnMouseDown does supply a X/Y.  Is there a cheap (i.e. efficient from a coding standpoint) of mapping the X/Y coord returned to the boundaries of the column header? ---------------------------------------------------------------------- wp · 2018-06-15 18:52 I guess you don't read what fred and I were writing... ---------------------------------------------------------------------- jbmckim · 2018-06-15 20:53 Sure I did.  (See  - "Those things didn't work" from my previous response.)  You left a question or two in your response though, perhaps not providing a context you assumed to be present. To be clear in this response, executing grid.MouseToCell(P.X, P.Y, myCol, myRow); from OnMouseDown changes/fixes nothing.  The problem remains as it was initially.  I may be wrong as to where/how you intended the snippet to be used but my take seems to be consistent with my previous questions.  Again, on my grid OnDblClick only executes when the double click occurs on the column title.  That would be fine, except that incurs the problem I'm asking about.  (i.e. Only executes after a cell on the grid has first been clicked.) Where do you intend that MouseToCell should be called from?  How are you proposing it be used?  It occurs to me that there is an off chance this might be an issue with my option set vs. yours.  Here's mine: 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 [goFixedVer tLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,go AlwaysShowEditor,goSmoothScroll] thanks. ---------------------------------------------------------------------- wp · 2018-06-15 21:39 In the attachment you find a working demo which show fred's and my ideas. You can select them with the radiobuttons at the bottom of the form. [EDIT] Attachment added. ---------------------------------------------------------------------- jbmckim · 2018-06-15 21:57 Sorry, I don't see an attachment. ---------------------------------------------------------------------- wp · 2018-06-15 22:04 added, sorry ---------------------------------------------------------------------- jbmckim · 2018-06-19 14:39 Thanks for the update. The relevance of the example puzzles me a bit.  I meant to be asking about issues trapping an event from a column header click (or double click) event.  The project posted doesn't show any grid events at all so I don't understand how it addresses the issue. Thanks again. ---------------------------------------------------------------------- wp · 2018-06-19 17:02 Then I cannot help you. To me the project clearly shows how a double- click on a header can be detected and evaluated to determine the column index. ---------------------------------------------------------------------- jbmckim · 2018-06-19 20:15 We must not be communicating.  My question regards the behavior of the SomeGrid.OnClick (or OnDblClick) event(s).  In your example, the grid does not implement those events so I don't understand how they're supposed to help.  All actions to the grid in the example drive off of push buttons. Anyone else care to give the question a go? ---------------------------------------------------------------------- jbmckim · 2018-06-19 20:44 Put another way,  here is code from my grid edited for purposes of what we're doing here: 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 TExitMainForm.InputStringGridDblClick(Sender: TObject);var  Reply, BoxStyle, ColNum, RowNum, i : integer;  strInput : string = '';  bReply : boolean = false;  iUserInt : integer = 0;  begin  ColNum := InputStringGrid.SelectedColumn.Index;  RowNum := InputStringGrid.Row; end;           Note " TExitMainForm.InputStringGridDblClick".  This is the grid's double click event.  (It also has a single click event.)  When I search the code for the project you uploaded, I do not find the strings "DblClick" or "GridClick."  Therefore, I do not understand how the example is supposed to answer my question.  This does not seem like an unreasonable question to me. ---------------------------------------------------------------------- wp · 2018-06-19 21:18 I'm sorry - I did upload the sample project of another thread that I was answering at the same time In the attachment there's the correct one (hopefully...) ---------------------------------------------------------------------- jbmckim · 2018-06-20 18:09 No problem. I'll check it out.  Thanks for the effort.