I'm try to get each ribbon tab on child form when its loaded to set the first tab (index 0) so the user would see this tab as the selected tab.
I read the following blog and tried it in VB.net:
>>> Ultratoolbarsmanager: How to programmatically activating a child tab
Here's my code:
==========================================================================
If Not activeChildManager Is Nothing Then
Dim parentTab As RibbonTab = childTab.AttachedParentTab
If Not parentTab Is Nothing Then
Else
End If
========================================================
But, [activeChildManager] is "Nothing" when I run the code
Note: the above code is located in the parent MDI form "MdiChildActivate" event.
Is the the correct location? (this is where I would like to manage all forms that load)
Have we missed something?
Thanks ahead of time.
Patrick
Hi Chris, thanks again for your help and prompt responses. This code does prevent the exception, however, the line to actually activate the child tab is never hit, so the child tab does not activate...?
Thanks Matt. I was able to reproduce the issue with the sample you provided. It appears that the code is causing a recursion issue where the OnMdiChildActivated() method is changing the SelectedTab, and then the AfterRibbonTabSelected event handler is activating a different child form. This causes the UltraToolbarsManager to step over itself as it recursively unmerges/merges the different ribbons.
Adding recursion flag seems to work in my sample. Just replaces the OnMdiChildActivate() override and AfterRibbonTabSelected event handlers with the following code:
Dim flag As Boolean
Protected Overrides Sub OnMdiChildActivate(e As EventArgs) MyBase.OnMdiChildActivate(e) 'Exception comes here
If Me.flag Then Return End If
If Me.tbrMain.ActiveMdiChildManager IsNot Nothing Then Me.tbrMain.Ribbon.SelectedTab = Me.tbrMain.ActiveMdiChildManager.Ribbon.Tabs(0).AttachedParentTab End If
End Sub
Private Sub tbrMain_AfterRibbonTabSelected(sender As Object, e As Infragistics.Win.UltraWinToolbars.RibbonTabEventArgs) Handles tbrMain.AfterRibbonTabSelected
Dim original As Boolean = Me.flag Try Me.flag = True Me.FiddleWithActiveWindowsBasedOnTabSelection(e.Tab) Catch ex As Exception Me.flag = original End Try End Sub
Let me know if this works for you.
Thanks,
Chris
OK. I brought in some code very similar to what we are using in the app and I was able to replicate the exception. In fact, it happens immediately upon starting the application. I'm still clueless as to what is actually causing this, but I found that if certain bits are commented out, the exception does not arise. I believe it is somehow related to the fact that the Home tab (the first tab on the parent ribbon) is always selected before the tab hosting the child tab is selected.
I've notated the attachment. I upgraded this project to 2014.2 FYI.
Please let me know what you are able to discover.
Thanks Chris. I have some stuff happening in the AfterRibbonTabSelected event - when I comment that out, I do not experience the issue. (Of course, then the application doesn't function as expected). When I figure it out, I will come back and post.
Hi Matt,
If you narrow down the cause of the issue with your application, please let me know. Hopefully we can add a fix for this scenario within our controls to avoid this issue in the future.
Additionally, if you have any other questions, feel free to ask.