TStringgrid Column Sizing lazarus / 31-LCL ---------------------------------------------------------------------- Weitentaaal · 2023-07-04 11:26 Hello, is it possible to reproduce the Excel Column sizeing-behaviour with a Stringgrid ? i cant get it done. If the Columns width gets over the grids width then there is some strange behaviour when resizing that column again. and when i set "ScrollBars" to ssAutoBoth and  "AutoFillColumns" to true then no Horizontal Scrollbar gets Displayed. Edit: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/24992 was this ever fixed ? thanks for any help ! ---------------------------------------------------------------------- jamie · 2023-07-04 13:03 Assuming you are using the COLOMNS property. 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 StringGrid1.Columns[1].SizePriority := 0;  That sets it so you can resize column 1 with all  your other resistrictions. Personally, I don't think you should need to use the Columns property to do this, there must be another way. I wanted to add that I don't think you are going to see scrollbars either way if you are filling the grid. ---------------------------------------------------------------------- Zvoni · 2023-07-04 13:10 Quote from: Weitentaaal on July 04, 2023, 01:26:37 pmHello, is it possible to reproduce the Excel Column sizeing-behaviour with a Stringgrid ? You mean this "double-click on the border of the header, and it resizes automagically" in Excel? I'd probably look at Canvas.TextWidth In a nutshell: Run through that column and look for the highest value of Canvas.TextWidth. In the ColumnHeader-DoubleClick event set the Width to that max. value incl. some margins ---------------------------------------------------------------------- wp · 2023-07-04 13:33 My observations on Windows: - Drop a TStringGrid on the form, set Align to alClient.  Double-click on the grid and enter some dummy data into some cells. - Probably the right edge of the right-most column is still inside the window. Reduce the width of the form: when the right side of the form hits the right-most column, a horizontal scrollbar appears, as expected. - Turn on the option goColSizing. - With the horizontal scrollbar visible, move the mouse in the header column bar close to the right edge of the form (but still inside). At some point, the cursor will change to a "resize" cursor - now you can drag and resize the last column even when its physical right edge is not visible. - Turn on the option goDblClickAutoSize. - Move the mouse in the header bar above the column divider between two columns so that the cursor become the "resize" type again. Double- click, and the left column (as seen from the cursor position) auto- sizes its width. Note that the correct spot is a bit hard to find, and it may require several attempts for this to work. So, in total: Very similar to Excel, I guess. ---------------------------------------------------------------------- Weitentaaal · 2023-07-04 13:38 Quote from: Zvoni on July 04, 2023, 03:10:13 pmQuote from: Weitentaaal on July 04, 2023, 01:26:37 pmHello, is it possible to reproduce the Excel Column sizeing-behaviour with a Stringgrid ? You mean this "double-click on the border of the header, and it resizes automagically" in Excel? I'd probably look at Canvas.TextWidth In a nutshell: Run through that column and look for the highest value of Canvas.TextWidth. In the ColumnHeader-DoubleClick event set the Width to that max. value incl. some margins no i meant the normal drag and drop to resize a column width. I have problems achieving the following: I want the columns to use up the whole width of the Control (-> AutoFillColumns: True) I want the uSer to be able to resize the Columns (-> options:goColSizing:Checked) I want Scrollbars when needed (i just found that i can use "ssBoth" instead of "ssAutoBoth" at the "Scrollbars" section) it kinda works when i enable those options, but other Options get blocked (or it seems like it). I want to have a min Col width so that the Colwidth can't be 0 or less. Solved that like this: 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.StringGrid2HeaderSized(Sender: TObject; IsColumn: Boolean;   Index: Integer);begin   if IsColumn then begin      if StringGrid2.Columns[Index].Width < 20 then         StringGrid2.Columns[Index].Width:= 20;   end;end; procedure TForm1.StringGrid2HeaderSizing(sender: TObject;   const IsColumn: boolean; const aIndex, aSize: Integer);begin   if IsColumn then begin      if aSize < 20 then         StringGrid2.Columns[aIndex].Width:= 20;   end;end;  Everything works, except for the Case when i make a Column exceed the Grids Width. Resizing it then gives me a strange behaviour. I can't make a Video but the Problem is easy to recreate. Edit: i checked why it feels that way and when resizing it does scroll at the same time horizontaly. Can i somehow disable Scrolling while resizing ? Eit2: When i push a Column out of the controls width and the Column is the Last, then i can't see its contents anymore ---------------------------------------------------------------------- wp · 2023-07-04 15:06 Quote from: Weitentaaal on July 04, 2023, 03:38:53 pmI want the columns to use up the whole width of the Control (-> AutoFillColumns: True) All columns having SizePriority=0 keep their assigned width. The remaining width of the grid is divided equally between all columns having SizePriority <> 0 (I think the individual non-zero values of SizePriority are not distinguished, in fact this feature would have been clearer if SizePriority would have been replaced by a boolean property "AutoSizeColumn"). Only the columns with SizePriority=0 can be actively resized by the user (by dragging the column at the right side of its header). But since due to resizing of such a column the remaining grid width changes, and the other columns (those with SizePriority<>0) will change their size as well. A bit confusing user experience. In particular because the mouse position gets out of sync with the dragged header side. Another annoying feature is that the resizing cursor appears also for the SizePriority<>0 columns which cannot be resized by dragging in AutoFillColumns mode. Quote from: Weitentaaal on July 04, 2023, 03:38:53 pmI want Scrollbars when needed (i just found that i can use "ssBoth" instead of "ssAutoBoth" at the "Scrollbars" section) This requirement contradicts the requirements for AutoFillColumns. When AutoFillColumns = true the entire width of the grid is filled by columns, and scrollbars cannot appear by definition. Well - normally. A horizontal scroll can appear neverthless, when a MinSize has been assigned to each column with SizePriority<> 0 and the total width of MinSize plus the current width of the SizePriority=0 column(s) is greater then the grid width. Quote from: Weitentaaal on July 04, 2023, 03:38:53 pmWhen i push a Column out of the controls width and the Column is the Last, then i can't see its contents anymore Move the mouse to the very edge of the right-most column header and drag it to the left. This may move in the lost column again. ---------------------------------------------------------------------- Weitentaaal · 2023-07-05 05:50 QuoteA bit confusing user experience. In particular because the mouse position gets out of sync with the dragged header side thats the problem i tried to describe  . All of my Columns are set to SizePriority = 0. I will make the Grid bigger and wont let the Columns combined width get bigger than the Controls width.