I have a project in VCL. I have connected the Grid to the database via Adapter and defined the columns. Everything works, but when I manually add the columns to the Grid to the right of them there is a blank space left. Setting the widht property of the column does nothing. Inside Delphi 12 it is OK, but when I run the application there is a blank space behind the columns on the right side (the columns do not fill to the width of the Grid). Am I doing something wrong?
Hi,
Can you indicate this with some kind of screenshot?
The empty space is just the left-over space from the component width minus the total width of the columns. If you keep adding columns, you'll get a scrollbar. This is by design. If you don't want this, and want the columns to fill the width of the component you need to turn on column stretching: Options.Column.Stretching.Enabled := True;
In my opinion, it does not work. If you set this property then the width property in the column stops working (no response to the value). If you leave it as it was there is created an empty space of whatever value you would not enter ( you can enter any value that fits on the screen). See how it works in DBGrid, but in short it's not on like here. Here you have no control over the width of the columns, or it's not the problem as you write. I'll look in the evening what the issue is, but for now it hasn't helped.
If you want to keep the width of the columns and stretch the last column you can swith to a different stretching mode:
Options.Column.Stretching.Enabled := True;
Options.Column.Stretching.Mode := gstmIndex;
I think you should take a close look at this. It doesn't work well with the VCL.
- If you don't have Streching enabled you see something completely different in the Design window and something different in the Application. There's nothing you can do about it, you're left with blank spaces and this is despite the fact that the blank space is not in the Design window.
- If you turn on Streching, what you see in the Design window is meaningless, because it aligns your last column, which looks rather bizarre in the Application. There isn't even an option to proportionally align columns.
My guess is that the problem mainly affects VCL, but there are nevertheless people who use it. I, for example.
Ok thanks, will investigate asap. One more question, which screen scale do you use?
We have further investigated this here, but the effect you see, is just the same as in DBGrid, except for an additional drawing which is called "empty space", it's drawn in the same way as the fixed rows and is created when the scrollbar is not stretched inside the grid, the scrollbar is placed within the normal cell area, the fixed cell area is ignored and this is the default behavior. If you want the same behavior as TDBGrid (or TStringGrid), set the property TMSFNCDataGrid1.StretchScrollBars
to True.
Additionally, there are 2 stretch modes. Stretches all columns to the width of the component, or stretches a specific column (set with the index property) to the remainder of the width.
The thing with designtime versus runtime differences is actually because there is a designtime panel that helps set some properties. If you don't want this, or set the column widths at designtime so it reflects properly at runtime, close the designpanel or set the property Designer
to False
I now take a moment to research the matter. I'll be back with a comment.
Bottom line. It's not like this. At the top in the picture Data Grid at the bottom DBGrid. It is more interesting. I checked additionally rDBGrid (RosiComp) because it is a derivative of DBGrid. It is fine everywhere, this strange Grid behavior is only with DataGrid in VCL.
In the picture we have three columns with widths of 400,400 and 270. Grid has a width of 1100. As you can see DBGrid is working just fine. DataGrid not.
Update1: I can already see one strongly puzzling behavior of the Adapter. There were three fields in the Adapter and when I pointed it to the DataGrid it made 4 columns.
Update2: Aha... I found a bug. You were somewhat right. The scaling is not working properly. Set your screen resolution to 125%. DBGrid works perfectly. Data Grid as in the image.
Thanks for the additional information, I'll investigate this here asap.
Fixed, next update will include DPI changes. it was indeed not correctly scaled. Thanks for reporting
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.