Automatically adjust the column of DBGRID to when

zhaozj2021-02-16  63

By default, the column width of DBGrid is adjusted according to the size of the database field. If the data table in our field is small, then it looks extremely unesthetic, so I wrote a function to adjust the column width of DBGRID. :

The function is as follows:

// make the content dbGrid automatically adapt to the width of his procedure MakeDBGridColumnsAutoFixItsWidth (objDBGrid: TDBGrid); var cc: integer; i, tmpLength: integer; objDataSet: TDataSet; aDgCLength: array of integer; begin cc: = objDbGrid.Columns.Count- 1; objdtaset: = objdbgrid.datasource.dataset; setlength (AdgClength, cc 1); file: // Take the length of the title field for i: = 0 to cc do begin adgclength [i]: = Length (objdbgrid.column I] .title.caption;

Objdataset.first; while not objDataSet.eof do begin file: // Take the length for I: = 0 to cc Do Begin TMPLENGTH: = Length (ObjDataSet.fields.fields [i] .sstring); if TMPLENGTH> Adgclength [i] THEN Adgclength [I]: = TMPLENGTH; END; ObjDataSet.Next;

For i: = 0 to cc do begin objdbgrid.columns [i] .width: = adgClength [i] * 7; end;

Simple test, efficiency can be accepted! (www.sinoprise.com)

转载请注明原文地址:https://www.9cbs.com/read-16328.html

New Post(0)