How to assign a component to a Delphi GridPanel row and column programmatically?

5.3k Views Asked by At

I am working on a project using Delphi where I am making rows and columns for a GridPanel dynamically. I am also creating a panel (TPanel) that I intend to place in each cell dynamically.

My question is: How do you assign the newly created panel to a particular cell that is in the GridPanel?

I am guessing that I have to assign the panel's "Parent" property so that it is the GridView. However, I have not been able to adjust a "Row" or "Column" property for the TPanel unlike when you able to when you assign a panel to the GridPanel using the design environment.

3

There are 3 best solutions below

1
On BEST ANSWER

How do you assign the newly created panel to a particular cell that is in the GridPanel?

The answer is, you can't. Adding new components to the TGridPanel, wether at design time or programmatically, places the new component in the next unoccupied cell. By default, in left to right order.

The ExpandStyle property (emAddRows or emAddColumns) determines how the TPanelGrid is expanded when filled, and further controls are added.

After you have added the new panel (or other component) to the TGridPanel you may change its position as others have answered, by accessing the control via the ControlCollection property.

0
On

You can access the property

TGridPanelLayout.ControlCollection[index].row := 0;

and

TGridPanelLayout.ControlCollection[index].Column := 0;
1
On

Use:

 TGridPanelLayout.ControlCollection[position].row := 0;