So, nach googeln und ausprobieren / verwerfen habe ich jetzt folgende "Lösung"
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
| procedure TForm1.ChangeColumnWidths(DBGrid: TDBGrid); var NewWidth, TotalColumnWidth, ColumnCount, GridClientWidth, StepWidth, i: integer; begin ColumnCount := DBGrid.Columns.Count; if ColumnCount = 0 then Exit;
TotalColumnWidth := 0; for i := 0 to ColumnCount-1 do TotalColumnWidth := TotalColumnWidth + DBGrid.Columns[i].Width; if dgColLines in DBGrid.Options then TotalColumnWidth := TotalColumnWidth + ColumnCount;
GridClientWidth := DBGrid.Width - GetSystemMetrics(SM_CXVSCROLL); if dgIndicator in DBGrid.Options then begin GridClientWidth := GridClientWidth - IndicatorWidth; if dgColLines in DBGrid.Options then Dec(GridClientWidth); end; if DBGrid.BorderStyle = bsSingle then begin if DBGrid.Ctl3D then GridClientWidth := GridClientWidth - 4 else GridClientWidth := GridClientWidth - 2; end;
if TotalColumnWidth < GridClientWidth then begin StepWidth := (GridClientWidth - TotalColumnWidth) div ColumnCount; for i := 0 to ColumnCount-1 do DBGrid.Columns[i].Width := DBGrid.Columns[i].Width + StepWidth; end else if TotalColumnWidth > GridClientWidth then begin StepWidth := (TotalColumnWidth - GridClientWidth) div ColumnCount; if (TotalColumnWidth - GridClientWidth) mod ColumnCount <> 0 then Inc(StepWidth);
for i := 0 to ColumnCount-1 do begin NewWidth := DBGrid.Columns[i].Width - StepWidth; if (NewWidth > 5) then DBGrid.Columns[i].Width := NewWidth; end; end; end; |
Aber die ersten 3 Spalten werden zu breit und alle anderen zu schmal dargestellt.
Noch nicht der Bringer!
Detlef
_________________
ut vires desint, tamen est laudanda voluntas