delphicontrolsassigntgridpanel

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


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.


Solution

  • 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.