Skip to main content
A newer version of this page is available. .

Expanding and Collapsing Groups

  • 2 minutes to read

When an Explorer Bar View is applied to the NavBar control, groups can appear collapsed or expanded. When a group is collapsed, item links within this group are not visible. The expanded state of a group is determined via its OptionsExpansion.Expanded property. At design time, you can double-click a group’s selector to change the group’s expanded state.

Local group is collapsed Local group is expanded

You can allow end-users to expand/collapse groups via the keyboard by adding accelerator keys to group captions. To add an accelerator key, place an ampersand (“&”) before a character in the group’s caption. This will allow end-users to press Alt+<character> combination to expand/collapse this group.

If the TabStop property is set to True, end-users can move through groups, item links, and an overflow panel‘s elements using the keyboard. Press Enter or Space while a group’s header is focused to expand/collapse this group.

The NavBar control behavior in Side Bar Views is similar to the behavior in Explorer Bar Views, except that the “expanded/collapsed group” term is replaced with “active/inactive group”. Item links within the active group are visible, and within the inactive group are not. Only one group can be active at a time. The state of a NavBar group for Side Bar Views is determined via the ActiveGroup or the ActiveGroupIndex property. At design time, you can double-click a group’s selector to make this group active.

You can also handle the OnActiveGroupChanged event to process changing of the active group.

To respond to group expanding and collapsing, handle the Group.OnExpanded and Group.OnCollapsed events. An example of the event handlers is demonstrated below. The example code expand/collapses all groups within the NavBar control according to the bgLocal group state:

procedure TfmFeaturesMain.bgLocalExpanded(Sender: TObject);
var
 I:Integer;
begin
with nbMain do
  begin
    for I := 0 to Groups.Count - 1 do
      if not Groups[I].OptionsExpansion.Expanded then Groups[I].OptionsExpansion.Expanded := True;
  end;
end;
procedure TfmFeaturesMain.bgLocalCollapsed(Sender: TObject);
var
 I:Integer;
begin
with nbMain do
  begin
    for I := 0 to Groups.Count - 1 do
      if Groups[I].OptionsExpansion.Expanded then Groups[I].OptionsExpansion.Expanded := False;
  end;
end;
See Also