Skip to main content

Navigating through Tabs

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

You can select a tab in code by setting the TabIndex property of the tab control to the desired tab index. The following sample code gets the index of the ‘Alignment‘ tab and selects it.

with cxTabControl1 do
  TabIndex := Tabs.IndexOf('Alignment');

If multiple tabs can be selected, the TabIndex property specifies the main tab index. The Selected property of a particular TcxTab object specifies whether the corresponding tab is selected. Please refer to the Handling Multiple Selections topic for details.

The OnChanging and OnChange events of the tab control fire immediately before and after a tab has been selected. You can use an OnChanging event handler to restrict tab selection when certain conditions are met. Consider the following sample code, which simply prohibits tab changes if the current tab index is 1.

procedure TForm1.cxTabControl1Changing(Sender: TObject;
  var AllowChange: Boolean);
begin
  if cxTabControl1.TabIndex = 1 then AllowChange := False;
end;