Quantcast
Channel: Atozed Forums - All Forums
Viewing all articles
Browse latest Browse all 268

Creating TIWGrid dynamically on a frame

$
0
0
I have a frame which I am displaying on four pages of a TIWTabControl. The four TIWTabPage pages are created dynamically, and as each one is created an instance of the frame is created and assigned to the page by setting its parent. There are some components such as TIWButtons on the frame and everything up to this point works perfectly.

I need to add a TIWGrid to the frame. I can place one on the frame in design time and it works but I can only update the grid on the first tab page. I figured out that this was because each instance of the grid must have a unique name. I tried setting the name in the IWFrameRegion create event but that did not work. It resulted in access violations.

So I then decided to create the grid dynamically, again in the IWFrameRegionCreate, and assign a unique name to each grid. This was partially successful.

Code:
  GrdHours := TIWGrid.Create(Self);
  ConfigureGrid(GrdHours, 'GrdHours', 335, 11);

And my ConfigureGrid method:

Code:
  procedure ConfigureGrid(AIWGrid: TIWGrid; AName: string; ATop: Integer; ALeft: Integer);
  begin
    AIWGrid.Parent := IWFrameRegion;
    AIWGrid.Name := AName + ComponentID.ToString;
    Inc(ComponentID);
    AIWGrid.Caption := '';
    AIWGrid.Left := ALeft;
    AIWGrid.Top := ATop;
    AIWGrid.Width := 377;
    AIWGrid.Height := 165;
    AIWGrid.UseFrame := False;
    AIWGrid.UseSize := True;
    AIWGrid.ShowEmptyCells := True;
    AIWGrid.ShowInvisibleRows := True;
    AIWGrid.ColumnCount := 4;
    AIWGrid.RowCount := 7;
    AIWGrid.ScrollToCurrentRow := False;
  end;

It works, and I can update the grid on each frame individually, BUT the problem is that all four grids are visible on the first tab page and none are visible on the other three tab pages.

I am creating some other components like TIWLabels using this same technique and there is no problem with them. Each tag page has its own instance of the label. 

To summarise: I create four instances of the tab page, and each page contains a dynamically created TIWGrid. All four instances of the grid are visible on the first tab page, and the other three tab pages do not show any grids.

Is there some other property of the grid I need to set to make it display on the tab page it belongs to?

Thank you!

Viewing all articles
Browse latest Browse all 268

Trending Articles