Category / Section
How to update the TabItemCollection when any one of its TabItem gets closed?
1 min read
To update the TabItemcollection when any one of its TabItemExt gets closed, set the CloseMode Property of TabControlExt to “Delete”.
CloseMode property:
The CloseMode is an enum that includes values as Hide and Delete that resides in the TabControlExt. When you click on the TabItemExt CloseButton and when the CloseMode is set to be Hidden, then the TabItemExt moves to the Hidden state. When the CloseMode is set to ‘Delete’, then the TabItemExt is removed from the TabControlExt, and it automatically gets deleted from the TabItems Collection.
You can achieve the above using the following code example.
XAML
// How to set the closeMode Property to delete <syncfusion:TabControlExt ItemsSource="{Binding TabCollections}" AllowDragDrop="True” CloseButtonType="Individual" CloseMode="Delete” EnableLabelEdit="False" SelectOnCreatingNewItem="True”> <syncfusion:TabItemExt Header=”NewTab”/> <syncfusion:TabItemExt Header=”NewTab1”/> <syncfusion:TabItemExt Header=”NewTab2”/> <syncfusion:TabItemExt Header=”NewTab3”/> <syncfusion:TabItemExt Header=”NewTab4”/> </syncfusion:TabControlExt>
The following is the Code Behind code example.
C#
//C# code demonstrates how to set the closemode property TabControlExt tab = new TabControlExt(); tab.CloseMode = CloseMode.Delete; TabItemExt tab1 = new TabItemExt(); TabItemExt tab2 = new TabItemExt(); TabItemExt tab3 = new TabItemExt(); TabItemExt tab4 = new TabItemExt(); TabItemExt tab5 = new TabItemExt(); tab1.Header = "FirstTab"; tab2.Header ="SecondTab"; tab3.Header = "ThirdTab"; tab4.Header ="FourthTab"; tab5.Header ="FifthTab"; tab.Items.Add(tab1); tab.Items.Add(tab2); tab.Items.Add(tab3); tab.Items.Add(tab4); tab.Items.Add(tab5); grid1.Children.Add(tab);