大佬教程收集整理的这篇文章主要介绍了delphi – 调整列宽DBGrid,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何设置“自动修复列宽”?
procedure FitGrid(Grid: TDBGrid); const C_Add=3; var ds: TDataSet; bm: TBookmark; i: Integer; w: Integer; a: Array of Integer; begin ds := Grid.Datasource.DataSet; if Assigned(ds) then begin ds.DisableControls; bm := ds.GetBookmark; try ds.First; SetLength(a,Grid.columns.Count); while not ds.Eof do begin for I := 0 to Grid.columns.Count - 1 do begin if Assigned(Grid.columns[i].Field) then begin w := Grid.Canvas.TextWidth(ds.FieldByName(Grid.columns[i].Field.FieldName).DisplayText); if a[i] < w then a[i] := w ; end; end; ds.Next; end; for I := 0 to Grid.columns.Count - 1 do Grid.columns[i].Width := a[i] + C_Add; ds.GotoBookmark(bm); finally ds.FreeBookmark(bm); ds.EnableControls; end; end; end; procedure TForm1.button1Click(Sender: TObject); begin FitGrid(DBgrid1) end;
以上是大佬教程为你收集整理的delphi – 调整列宽DBGrid全部内容,希望文章能够帮你解决delphi – 调整列宽DBGrid所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。