[CLOSED] DBGrid Autosize lazarus / 16-Databases ---------------------------------------------------------------------- egsuh · 2020-07-17 05:39 I'd like to show DBGrid in the way that last column fill to the end, with previous columns are auto fit to each width (this is done by setting dgAutoSizeColumns true). But once I set property AutoFillColumns=true, then all columns are divided evenly.  Is there any way that I can set only the last column take to the end? ---------------------------------------------------------------------- emilt · 2020-07-17 06:39 Maybe you should check the TGridColumn.SizePriority property. ---------------------------------------------------------------------- balazsszekely · 2020-07-17 06:49 Hi egsuh, Please test the following code, but first set dgAutoSizeColumns to false. In this example the last column is 4, you can change it according to your needs. 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 type   TForm1 = class(TForm)  //...  procedure FormCreate(Sender: TObject);  procedure SQLQuery1AfterOpen(DataSet: TDataSet);  private    procedure AutoSnapColumn(AGrid: TDBGrid; AColumn: Integer);    procedure GridResize(Sender: TObject);  public   end;  implementation procedure TForm1.FormCreate(Sender: TObject);begin  DBGrid1.OnResize := @GridResize;end; procedure TForm1.GridResize(Sender: TObject);begin  AutoSnapColumn(DBGrid1, 4);end; procedure TForm1.SQLQuery1AfterOpen(DataSet: TDataSet);begin  AutoSnapColumn(DBGrid1, 4);end; procedure TForm1.AutoSnapColumn(AGrid: TDBGrid; AColumn: Integer);var I: Integer; W: Integer;begin  if AColumn > AGrid.Columns.Count - 1  then    Exit;  W := 0;  for I := 0 to AGrid.Columns.Count - 1 do    if I <> AColumn then      W := W + AGrid.Columns[I].Width;  if dgIndicator in AGrid.Options then    W := W + DEFINDICATORCOLWIDTH;  AGrid.Columns[AColumn].Width := AGrid.ClientWidth - W;end; ---------------------------------------------------------------------- egsuh · 2020-07-18 05:45 @GetMem, Your approach must be a generic solution. But I solved my problem in following way. 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 TSelectOpenCF.bdsOpenCFListAfterOpen(DataSet: TDataSet);var   pw, ti : integer;begin   pw := 30;   for ti := 0 to bdsOpenCFList.FieldCount-2 do       pw += DBGrid1.Columns[ti].Width + 2;   DBGrid1.LastColumn.Width := DBGrid1.Width - pw ;end;  Do not ask me why 30 and 2. They just fit my case.