20

I want to use Delphi's 2009 TGridPanel, but I don't understand how to use it correctly.

For example, I want to have a GridPanel with 4 columns which should have each 25% percent of the GripPanels width.

So I put a GripPanel on the form and add 4 ColumnItems. I give the column items SizeStyle ssPercent, and now I try to give each ColummItem a Value of 25 (ober the object inspector). But for some reasons the object inspector doesn't accept the value 25. It's automatically changed to something like '23,8095238095238'. Could somebody explain me in short how to use this components? Thanks!

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
flinkiy1
  • 267
  • 1
  • 3
  • 7

2 Answers2

18

If you want to set all columns to the same value, select all columns in the structure view and then (assuming SizeStyle is already set to ssPercent) set the Value to 0. This will trigger some automatism that makes all of the columns sized equal.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
15

When you set the Value of a column with SizeStyle ssPercent, the component distributes the new sum of all ssPercent styled columns for the available total percentage. For instance, if you've got 4 25% columns and you set one to be 50% now you've got a total of 125%. The component calculates 'Value's again to have the total distributed proportionally, i.e. 50% -> 40% (100*50/125) .

To set the value of more than one columns at once, at run time you'd surround your code with GridPanel.ColumnCollection.BeginUpdate and GridPanel.ColumnCollection.EndUpdate.

And at design time edit the .dfm directly. Press 'Alt+F12' when you're viewing your form in the design editor, find your GridPanel in the text editor, edit the value of the columns there, and then press 'Alt+F12' again to return to the design view.

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
  • Thanks, that works! On note: After dropping a GridPanel on the form and deleting the rows and colums at designtime, these rows and columns still exist on runtime and you have to delete them manually. Little bit strange. – flinkiy1 Oct 07 '10 at 10:19
  • Or you can select all 4 columns and write 25 in object inspector – VitaliyG Sep 02 '13 at 12:46
  • 1
    @Vitaliy - That is not easier than selecting all 4 and then typing 0, which is covered in Uwe's answer. My answer, rather, is helpful if you're not going to equally distribute the widths. Of course you can also do that but, indeed, other alternatives are better at that. – Sertac Akyuz Sep 02 '13 at 18:19