Skip to main content

Managing the Pages Collection

  • 2 minutes to read

The TcxPageControl control maintains a collection of pages. This topic covers the ways in which to manipulate tabs in the collection.

First of all, it is worth noting that each page is represented by a TcxTabSheet control. The PageControl property of this object specifies the control to which a page belongs. Thus it is necessary to create a new TcxTabSheet object and set its PageControl property in order to add it to the desired page control.

For instance, you can declare the following procedure that adds a new page with the specified caption to the specified control.

procedure AddPage(ACaption: string; AControl: TcxPageControl);
var NewPage: TcxTabSheet;
begin
  NewPage := TcxTabSheet.Create(AControl.Owner);
  NewPage.PageControl := AControl;
  NewPage.Caption := ACaption;
end;

You can now use the following sample code to add three pages to a page control.

AddPage('First Page', cxPageControl1);
AddPage('Second Page', cxPageControl1);
AddPage('Third Page', cxPageControl1);

The image below displays the result of code execution:

The order of pages can be changed via the PageIndex property of the TcxTabSheet object. Note, that pages are accessed via the Pages property of the TcxPageControl control. The total number of pages is returned by the PageCount property.

The following sample code moves the last added page to the first position.

cxPageControl1.Pages[2].PageIndex := 0;

Execution of the code listed above will appear as follows:

There are two ways to remove pages from a page control. The first is to set the PageControl property of the TcxTabSheet object to nil. The second is to destroy the page via the Free method.

The following sample code removes the first and the last pages.

cxPageControl1.Pages[2].PageControl := nil;
cxPageControl1.Pages[0].Free;

Execution of the code listed above will appear as follows: