0
votes

I am trying to add multiple controls to a drawgrid. I can add the controls, but after adding them and scrolling, the control paint in different cells.

Here's the code I'm using to add the controls to my drawgrid:

void __fastcall TForm1::Button1Click(TObject *Sender) {

pnlHierBox = new TPanel(this); //defined at the class level

pnlHierBox->Left = 0;
pnlHierBox->Top = 0;
pnlHierBox->Width = 180;
pnlHierBox->Height = 120;

img = new TImage(pnlHierBox);
img->Picture = Image1->Picture;
img->Left = 0;
img->Top = 3;
img->AutoSize = true;
img->Parent = pnlHierBox;

     lbl = new TLabel(pnlHierBox);
lbl->Caption = "Employee 1";
lbl->Left = 24;
lbl->Top= 15;
lbl->Parent = pnlHierBox;

icon = new TImage(pnlHierBox);
icon->Picture = Image2->Picture;
icon->Left = 100
icon->Top = 63;
icon->AutoSize = true;

icon->Parent = pnlHierBox;
rect = DrawGrid1->CellRect(2,0);
     pnlHierBox->Top = rect.Top;
     pnlHierBox->Left = rect.Left;

     DrawGrid1->InsertControl(pnlHierBox);

// Add other TPanel controls to the drawgrid
//

}

1

1 Answers

0
votes

Don't call InsertControl() directly. Use the Parent property instead:

// DrawGrid1->InsertControl(pnlHierBox);
pnlHierBox->Parent = DrawGrid1;