Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofill columns based on size of grid 1

Status
Not open for further replies.

tsd30135

Technical User
Sep 21, 2004
38
US
I want to make the dbgrid the width of my form for readability sake. I am filling the grid with a recordset but I want the columns to take up the whole size of the grid.

If there are only 2 fields in the recordset then the 2 columns would be large. etc...

What is the best way to program this?

tsd
 
Manually, analyze the data before populating then set the width like so:

DataGrid1.Columns(0).Width = SomeValue
DataGrid1.Columns(1).Width = SomeOtherValue
etc.

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Thanks for the suggestion. I want to fill the grid with columns based on the number of fields in my recordset.

If I have 5 fields in my recordset I want 5 columns to fill the grid.

tsd
 
Then something like this should get you started.


for i = 0 to FieldCount - 1
DataGrid1.Columns.Add(i).Caption = FieldName(i)
DataGrid1.Columns(i).Width = OverAllWidth / FieldCount
next i

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Thanks that will help. You get a star
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top