[SOLVED] StringGrid Horizontal scrollbar always present lazarus / 31-LCL ---------------------------------------------------------------------- indydev · 2024-01-22 20:07 I am dynamically creating a StringGrid placing it into a TPanel and assigning it to a private Field (thus it is called FTable). The TPanel itself is dynamically created. The data for the StringGrid data is assigned from a streamed source (and handled elsewhere). The StringGrid displays fine, and correctly displays the data. However, no matter what I do, I can't get the Horizontal Scrollbar to disappear. ssNone does not work.  ssAutoHorizontal and ssAutoBoth, even if I resize the StringGrid still displays the horizontal scrollbar. The vertical scrollbar works correctly--or at least how I expect it to. I have included the entire procedure code just in case, but much of it is probably irrelevant to the issue. I am using Linux Mint 21.2. 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 TDiscussionPanel.CreateTable(MLeft, MWidth: integer; DText: string);const  border = 8;var  tblData: TTableData;  i, j, TotalWidth: integer;begin  tblData := ParseMarkdownTable(DText);  FTable := TStringGrid.Create(Parent);  FTable.Parent := Self;  FTable.ScrollBars:=ssNone;  FTable.Font.Size := 12;  FTable.DefaultRowHeight := (FTable.Font.Size + 1) * 2;  Self.Height := FTable.DefaultRowHeight * tblData.RowCount;  FTable.FixedRows:=0;  FTable.RowCount := tblData.RowCount;  FTable.ColCount := tblData.ColCount;  FTable.Flat := TRUE;  FTable.ParentColor:=TRUE;  FTable.BorderColor := clBlueSilver;  FTable.Options:=[goFixedHorzLine, goFixedVertLine, goHorzLine, goRangeSelect, goVertLine];  FTable.FixedCols:=0;   if tblData.Header then begin     FTable.FixedRows:=1;     FTable.FixedGridLineColor := clBlueSilver;   FTable.OnPrepareCanvas := @TablePrepareCanvas;   end;  FTable.GridLineColor := clBlueSilver;  FTable.TitleFont.Color := clBlueSilver;  FTable.Font.Color := clBlueSilver;  TotalWidth := 0;  for J := 0 to tblData.RowCount - 1 do begin    for i := 0 to FTable.ColCount - 1 do begin      FTable.Cells[i, j] := tblData.ColRow[i, j];      if j = FTable.RowCount - 1 then begin       FTable.AutoSizeColumn(i);       TotalWidth := TotalWidth + FTable.ColWidths[i];      end;    end;  end;  FTable.Width := TotalWidth + 1;  FTable.Height:= (FTable.DefaultRowHeight + 1) * (FTable.RowCount + 2);  FTable.Anchors:=[akTop, akBottom];  FTable.AnchorSide[akTop].Control := FTable.Parent;  FTable.AnchorSide[akTop].Side := asrTop;  FTable.AnchorHorizontalCenterTo(Parent);  FTable.AnchorSideBottom.Control := FTable.Parent;  FTable.AnchorSideBottom.Side := asrBottom;  FTable.BorderSpacing.Left := border;  FTable.BorderSpacing.Right:= border;  FTable.BorderSpacing.Bottom:= border;  FTable.BorderSpacing.Top:=border;  FLeft := MLeft;  FWidth:= MWidth;  FTable.Left := FLeft + (FWidth - FTable.Width) div 2;end; ---------------------------------------------------------------------- wp · 2024-01-22 22:30 Can you extract the issue into a small compilable project? Pack .pas, .lfm, .lpr and .lpi files into a common .zip and upload that under "Attachments and other options" (do not include any compiler-generated files, please). ---------------------------------------------------------------------- madref · 2024-01-23 00:00 A TStringGrid has the options of Scrollbars (See attachment). You can uses this to set or not to set the scollbyrs Or add to your TotalWidth 10 instead of 1 and run it and see what happens. If the horizontal scrollbar is still there increase it to get the right with. If it's gone do the same but decrease is. It's sometimes a bit of trial and error ---------------------------------------------------------------------- indydev · 2024-01-23 02:38 I have attached a zip with a simple form and a button to dynamically create a TPanel and a TStringGrid. @madref  The scrollbars property is not working correctly in this case. ssNone, ssAutoHorizontal, ssAutoBoth all leave the Horizontal scrollbar no matter the width. ssAutoVertical works however. ---------------------------------------------------------------------- wp · 2024-01-23 10:16 Could not reproduce the issue on Windows, but on Linux Mint I could. Playing with the issue for a while I found out, that the scrollbar goes away when the Scrollbars property is set before setting the Parent: 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    NewPanel.FTable := TStringGrid.Create(Parent);   NewPanel.FTable.ScrollBars:=ssNone;    // Must be before setting the Parent    NewPanel.FTable.Parent := NewPanel;      ... ---------------------------------------------------------------------- indydev · 2024-01-23 15:13 I can confirm your solution on Linux Mint. I moved the scrollbars setting around many places, but didn't try that. Thank you! I don't have a Windows machine here, and eventually I will have to test on Windows. Do you know if this messes anything up on Windows? ---------------------------------------------------------------------- wp · 2024-01-23 15:34 Quote from: indydev on January 23, 2024, 04:13:22 pmI can confirm your solution on Linux Mint. I moved the scrollbars setting around many places, but didn't try that. Thank you! I don't have a Windows machine here, and eventually I will have to test on Windows. Do you know if this messes anything up on Windows? No, your project was fine on Windows (with setting scrollbars before or after setting the Parent) ---------------------------------------------------------------------- indydev · 2024-01-23 15:59 Great!