TMSFNCGrid Column resize according the the longest column value

Hello,

I have read quite a few post about column resize but somehow the solutions don't work for me.
Here is the scenario:

  • I have a grid, which I create on the fly, selecting data from a database table on the fly
  • There are many columns and the width of the columns might differ even for the same table depending on the data.
    Consider that if I have customer names like: "Bob Doe","Jim Bain","Tim Cole" then the width of the column is relatively short. But if the names are like "Hubert Blaine Wolfeschlegelsteinhausenbergerdorff" or " Benjamin Alexander Ottovordemgentschenfelde" then obviously the column should be much wider.

Obviously I cannot know in advance the width of the longest column.
Previously I used Quantumgrid from Devexpress which has a nice function: it searches for the longest value of a column and stretches a column (or multiple columns) accordingly. Is this possible with TMSFNCGrid?

So far I tried this:

Grid.AutoSizeColumns; -> This resized random columns: a few were resized well, but most weren't. Please have a look at the attached screenshot: Tms01.png

Then I tried this:

          MyFncGrid.Options.ColumnSize.StretchAll := False;
          MyFncGrid.Options.ColumnSize.StretchColumn := 2;
          MyFncGrid.Options.ColumnSize.Stretch := True;

and also played with the order

          MyFncGrid.Options.ColumnSize.StretchAll := False;
          MyFncGrid.Options.ColumnSize.Stretch := True;
          MyFncGrid.Options.ColumnSize.StretchColumn := 2;

But for me it didn't do anything. Also the documentation doesn't say anything about Options.ColumnSize.StretchColumn or about Grid.StretchColumn that should I use the index of the column? If so what if I want to resize the second, the fifth and the seventh columns?

Thank you very much for your help!

Hi,

Stretching is something different than autosizing. if you enable stretching, and set stretchall to false, it will only stretch the column width based on the StretchColumn property. When calling AutoSizeColumns this will not have any effect whatsoever, because stretching is enabled. Stretching will take the available width of the grid, divide that by the number of columns and set each column to the result of that division. If you want to auto size the column, you can just set ColumnSize.Stretch to false and call AutoSizeColumns, which should automatically size all columns to the content.

Thank you, Pieter