Hello,
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:
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