[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Collapse]Layout Management
   [Expand]Dock Windows
   [Expand]Tile and Layout
   [Collapse]Tab Control
    [Expand]Product Information
    [Expand]Fundamentals
    [Collapse]Concepts
      Binding to Data Overview
      Selecting Tab Items
      Showing and Hiding Tab Items
      Adding and Removing Tab Items
      Header Menu
      Appearance Customization
    [Expand]Examples
   [Expand]Carousel
    Book Control
    Workspace Manager
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Adding and Removing Tab Items

The DXTabControl has the Hide and New buttons that provide end-users with the capability to hide\add tab items.

Expanded Adding Tab items

The New button's location depends on the TabControlViewBase.NewButtonShowMode property. Below is a list of all possible locations.

  • NoWhere - the New Button is not shown.

  • InHeaderArea - the New Button is located inside the Header Area.

  • InTabPanel - the New Button is located inside the Tab Panel, next to tab item headers.

  • InHeaderAreaAndTabPanel - the New Button is shown in the Tab Panel and Header Area simultaneously.

The example illustrating how this property works is available in our Interactive Demos in the Utility Controls | Tab Control | Views section.

Tab Control provides two ways to add new items by clicking the New button: using its own adding logic and manually. In the first way, when an end-user clicks the New button, the tab control creates a new tab item on its own. The mechanism of creation and the strategy for adding new items depends on how the tab control is populated.

  • When items are initially defined via the Items property, tab control creates a new instance of the DXTabItem type and adds it to the DXTabControl.Items collection.
  • When items are generated based on a collection assigned to the ItemsSource, tab control chooses the mechanism of adding new items based on the data source.

    • If the source collection implements the IBindingList interface, tab control uses its AddNew method to add an item.
    • If the source is an IList implementation, the tab control determines the type of collection objects and adds an instance of the corresponding type to the source.

      Note

      The underlying source should provide notifications when new items are added, otherwise, corresponding tabs won't be displayed within the tab control.

To control adding new items, you can handle the DXTabControl.TabAdding and DXTabControl.TabAdded events.

The DXTabControl.TabAdding event is raised by the tab control, before the new item is added. In this event, you can manually initialize the newly created item or cancel adding by setting the e.Cancel property to true.

The code snippet below illustrates how to initialize the newly created item.

If you use your own data source that doesn't implement the IList or IBindingList interface, you can handle the DXTabControl.TabAdding event to disable the default mechanism and write your custom logic.

After the new item is added, tab control raises the DXTabControl.TabAdded event. It allows you to customize the newly added item located in the e.Item property, perform selection, etc.

In the second way, you can add new items by using the TabControlViewBase.NewTabCommand property that works by bypassing the Tab Control's adding mechanism. If a command is assigned to the NewTabCommand property, Tab Control invokes the specified command when the New button is clicked. In this command, you can implement any required adding logic specific to your underlying data source.

Note

Since the TabControlViewBase.NewTabCommand property works by bypassing the internal Tab Control's adding logic, the DXTabControl.TabAdding/DXTabControl.TabAdded events won't be raised.

To programmatically create a new item, you can use the DXTabControl.AddNewTabItem method.

Expanded Tab item removal (hidding)

Location of the Hide button is specified using the TabControlViewBase.HideButtonShowMode property.

  • NoWhere - the Hide button is not shown.

  • InAllTabs - the Hide button is shown in all tab headers.

  • InActiveTab - the Hide button is shown in the active tab header only.

  • InHeaderArea - the Hide button is shown in the Header Area.

  • InAllTabsAndHeaderArea - the Hide button is shown in all tab headers and in the Header Area.

  • InActiveTabAndHeaderArea - the Hide button is shown in the active tab header and in the Header Area.

The example illustrating how this property works is available in our Interactive Demos in the Utility Controls | Tab Control | Views section.

Tab item closing is performed in two phases: hiding and removing. The first one is responsible for the tab item hiding that is performed in the following manner. Before the tab item is hidden, tab control raises the cancellable DXTabControl.TabHiding event. If the hiding action has not been canceled, tab control hides the specified tab item and raises the DXTabControl.TabHidden event. After that, the hidden item invokes its DXTabItem.CloseCommand. There, you can implement your own closing\removing logic. The command's CanExecute state corresponds to the Hide button accessibility. If an item has been successfully hidden and tab control has the TabControlViewBase.RemoveTabItemsOnHiding property set to true, the tab control removes the item. The Tab control raises the cancellable DXTabControl.TabRemoving event before the item is removed and the DXTabControl.TabRemoved event after the item is removed successfully.

To programmatically remove an item, you can use the DXTabControl.RemoveTabItem method.

Is this topic helpful?​​​​​​​