Enabling stretching enables automatic column calculation for all columns to the available width of the control. You can auto stretch a single column and manipulate the others by changing the stretch mode.
I would like to trim all columns to their maximum required width with following code:
GlobalFont.Name := FontNameGlobal; // Font des Grids setzen
Options.Filtering.Enabled := True; // Filter im Header einschalten
Options.Sorting.Enabled := True; // Sortierung im Header
Options.Selection.Mode := gsmSingleRow;
DefaultColumnWidth:=100;
Options.Column.Stretching.Enabled:=True;
Options.Column.Stretching.Index := -1;
Options.Column.Stretching.Mode := gstmAll;
But the Width of all columns is then 100, also those with a maximum needed width of 50.
Another possibility would be to delete all columns and only add the required columns with their widths and set Strech to false.
What code would be necessary for this.
If i call AutoSizeColumns outside of my initialization procedure then it works fine.
But if i would add my Columns separate to the DataGrid that is bound to an Adapter that is bound to a Database.
How to add a Column to the Grid with the Fieldname Nachname:
AutoCreateColumns = False, and you have 0 columns in the grid, you can tell the database adapter which fields you want and where you want them to be, then it's only required to execute this code: