I would like to create a "New Tab" tab (similar in function to IE 7 new tab button). This Tab, when clicked, creates an additional tab by adding an object to the underlying datasource. I don't seem to be able to add a tab directly to a databound UltraWinTabControl so I created a "fake" object and added that to the datasource.
My code:
Private Sub LinesTabs_ActiveTabChanging(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinTabControl.ActiveTabChangingEventArgs) Handles LinesTabs.ActiveTabChanging
If e.Tab.Text = "Add" Then e.Cancel = True 'prevent add tab from being switched to 'add new object to datasource End If
The problem is the Add tab is automatically selected when there is no other tabs (either because it is the only tab that exists in the UltraWinTabControl or it becomes that way by removing all other tabs). This fires the add new object code without the tab being clicked on.
...How do I go about making this work? or is there some better way of achieving similar functionality
I figured it out. Here's what I did for anyone else who cares
'disable ActiveTabChanging event LinesTabs.EventManager.SetEnabled(Infragistics.Win.UltraWinTabControl.UltraTabControlEventId.ActiveTabChanging, False)'Add the fake Add Tab to datasource here'CODE REMOVED'Unselect all tabsLinesTabs.SelectedTab = Nothing
'enable ActiveTabChanging event LinesTabs.EventManager.SetEnabled(Infragistics.Win.UltraWinTabControl.UltraTabControlEventId.ActiveTabChanging, True)
Private Sub LinesTabs_ActiveTabChanging(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinTabControl.ActiveTabChangingEventArgs) Handles LinesTabs.ActiveTabChanging If e.Tab.Text = "Add" Then e.Cancel = True 'Code for Adding Tab goes here End ifEnd Sub
The problem there is when you start with an empty collection (besides the "Add" tab) you can't ever create the first tab because Count = 1...the add tab.
My above code would work if I could bind the datasource to the list and have no tabs initially selected (All without the ActiveTabChanging event being fired)
Instead of just checking e.Tab.Text = "Add" in the if statement, you can add an additional check:
e.Tab.Text = "Add" AndAlso e.Tab.TabControl.Tabs.Count > 1