1

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Andre72127
  • 219
  • 3
  • 11

3 Answers3

1

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 it's position as others have answered, by accessing the control via the ControlCollection property.

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
1

Use:

 TGridPanelLayout.ControlCollection[position].row := 0;
  • 2
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Badacadabra May 27 '17 at 13:16
0

You can access the property

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

and

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