Skip to main content

Navigating through Pages

  • 2 minutes to read

The TcxPageControl control maintains a collection of pages, which can be selected by a user by clicking corresponding tabs. This topic covers the ways in which to select pages in code. It also describes events which fire before or after a page has been selected.

You can select a page by setting the ActivePage property to the TcxTabSheet object representing the desired page. The same can be achieved by setting the ActivePageIndex property to the desired page index. The following two lines of code are equivalent:

cxPageControl1.ActivePageIndex := 1;
cxPageControl1.ActivePage := cxPageControl1.Pages[1];

Note

Setting the described properties can result in activating a page, whose tab is invisible (the TabVisible property of the corresponding TcxTabSheet object is False). All visible tabs become deselected in such a case.

Another way of selecting pages is using the SelectNextPage method of the TcxPageControl control. It allows you to select the previous or next page to that currently selected. The following line of code selects the next page. Pages with invisible tabs are ignored when searching since the method’s second parameter is not specified.

cxPageControl1.SelectNextPage(True);

The OnChanging and OnChange events of the tab control fire immediately before and after a page has been selected. These are derived from the TcxCustomTabControl class. The TcxPageControl class introduces an OnPageChanging event which fires before the active page changes. The OnChanging and OnPageChanging events can be used to prohibit navigation. Consider the following code, which restricts navigation to the first page.

procedure TForm1.cxPageControl1PageChanging(Sender: TObject;
  NewPage: TcxTabSheet; var AllowChange: Boolean);
begin
  if NewPage.PageIndex = 0 then AllowChange := False;
end;

You can also perform specific actions when a page becomes active or inactive. Use the OnShow or OnHide event of the TcxTabSheet object for this purpose.