Skip to main content

Handling Multiple Selections

  • 2 minutes to read

The TcxTabControl control allows an end-user to select multiple tabs. This topic describes the way to implement this feature. It also covers the ways of selecting multiple tabs in code and determining which tabs are selected.

The following conditions must be met to enable the multi select feature:

If the conditions above are satisfied, end-users can select multiple tabs when holding the Ctrl key pressed. Clicking a selected tab when the Ctrl key is pressed deselects the tab.

The following sample code provides a multi select feature to the end-users:

with cxTabControl1 do
begin
  MultiSelect := True;
  SetStandardStyle(tsButtons);
end;

The Selected property of the TcxTab object specifies whether the tab is selected. The following sample code deselects all tabs and then selects the first and third tabs. Note that it is necessary to set the TabIndex property to -1 in order to deselect the main tab:

var i: Integer;
// ...
with cxTabControl1 do
begin
  TabIndex := -1;
  for i := 0 to Tabs.Count - 1 do
    Tabs[i].Selected := False;
  Tabs[0].Selected := True;
  Tabs[2].Selected := True;
end;

The Selected and IsMainTab properties of the TcxTab object are used to determine the selected and main tabs. If the IsMainTab property returns True, the corresponding tab is the main tab. Note, that the Selected property returns False for the main tab.

var i: Integer;
// ...
with cxTabControl1 do
begin
  for i := 0 to Tabs.Count - 1 do
  begin
    if Tabs[i].Selected then
    begin
      // selected tab
    end;
    if Tabs[i].IsMainTab then
    begin
      // main tab
    end;
  end;
end;