I have problem with column width in dbgrid in delphi. I get result from database and i has three columns ID
, Name
, Description
.
Name and description has width about 2000+
. I try to change in DBGrid > Columns > description > width = 300
but not work. Again when i compaile my columns has to much width
. How to slove this? I want to be ajusted in parent.
Asked
Active
Viewed 4,742 times
-2

Blorgbeard
- 101,031
- 48
- 228
- 272

Ivan
- 5,139
- 11
- 53
- 86
-
I've never had this problem, and I routinely deal with DB fields that are very wide (including memo fields containing thousands of characters). How can we reproduce this problem? – Ken White Aug 29 '16 at 23:43
-
Does f.ex. `DBGrid.Columns[1].Width := 100;` work? – Tom Brunberg Aug 30 '16 at 06:45
2 Answers
0
It is necessary to add columns object.
By IDE: right click on DBGrid, columns editor then "Add all fields..." By runtime: you must create a Column objects.
This is a small example:
var vColumn: TColumn;
begin
vColumn := DBGrid1.Columns.Add;
// Now you can assign the right properties
vColumn.Field := yourfield
vColumn.Width := yourwidth

Lorenzo
- 99
- 5
-
Loking at the image, it appears that the grid already has the columns. What good does it do to add more columns? – Tom Brunberg Aug 30 '16 at 07:19
-
If you haven't create any TColumn DBGrid show always all columns available in dataset. It's not clear if the change of width is made by IDE or runtime = maybe no Column objects are created – Lorenzo Aug 30 '16 at 07:24