StringGrid with one fixed column and one non-moveable, editable column lazarus / 31-LCL ---------------------------------------------------------------------- Craig · 2018-05-21 13:38 Hi All, I am trying to create a table with one fixed column (i.e. FixedCols:=1) in position 0, one drop-down column in position 1, and several "data" columns after that. I would like the "Data" columns to be movable (i.e. goColMoving := true) but do not want the drop-down column to be moved from position 1. I have tried to catch when column 1 is moved as such: 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.StringGrid1ColRowMoved(Sender: TObject; IsColumn: Boolean;              sIndex, tIndex: Integer);begin   if (sIndex=1) or (tIndex=1) then      begin         //ShowMessage('sIndex: '+IntToStr(sIndex)+'    tIndex: '+IntToStr(tIndex));         if not HasSwapped then          begin               HasSwapped:=true;               StringGrid1.MoveColRow(IsColumn,sIndex,tIndex);            end       else            HasSwapped:=false;      end;end;  The StringGrid1.MoveColRow triggered the event again (causing an infinite loop) hence the requirement for the "HasSwapped" flag. The above code does not work, I believe because the event is triggered before the columns are swapped. Does anyone have any suggestions for me, or is this beyond the capability of s StringGrid? Thanks! Craig ---------------------------------------------------------------------- Blaazen · 2018-05-21 14:18 @ Does anyone have any suggestions for me, or is this beyond the capability of s StringGrid? IMO beyond the capability. Maybe workaround would be to place two buttons by the grid with arrows <- and ->. Those buttons will be enabled only when column >=2 is selected and will move the column to the left/right by one. EDIT: Or movable columns will have popup menu with items for moving, just like tabs of Lazarus source editor. ---------------------------------------------------------------------- wp · 2018-05-21 15:29 This is a bit "hacky" but seems to work: Simply turn off goColMoving if the mouse is pressed or moved above the header of column 1, and call Abort to shut down the current dragging action 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.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);var  cell: TPoint;begin  cell := StringGrid1.MouseToCell(Point(X, Y));  if (cell.Y = 0) and (cell.X = 1) then begin    StringGrid1.Options := StringGrid1.Options - [goColMoving];    Abort;  end else    StringGrid1.Options := StringGrid1.Options + [goColMoving];end;This is to be hooked into the OnMouseDown and OnMouseMove events of the grid. ---------------------------------------------------------------------- Craig · 2018-05-22 08:54 Thank you both for your help. Quote from: Blaazen on May 21, 2018, 04:18:16 pmOr movable columns will have popup menu with items for moving, just like tabs of Lazarus source editor. Blaazen, I was just about to implement this suggestion  Quote from: wp on May 21, 2018, 05:29:21 pmThis is a bit "hacky" but seems to work: Simply turn off goColMoving if the mouse is pressed or moved above the header of column 1, and call Abort to shut down the current dragging action WP, thank you for the brilliant suggestion. It seems to work very well. I would never have thought of trying that.