I'm currently working on a project that's using the Infragistic ribbon controls. The basic layout of the "main" form in the project is a form with a ribbon and a standard TabControl. Once the application is started, it dynamically adds one of our custom controls into the first tab in the TabControl. The idea is to use the tabs so we can have multiple instances of our custom control running all with different data. In our custom control, we have a bunch of listboxes for selection and whatnot. To clear up some space, we wanted to move these listboxes to the ribbon. Currently, we're doing this by using the PopupControlContainer tool in the ribbon. We have getters in the custom control so the main has direct references to the listboxes in the control. So far so good. The PopupControlContainer is working as intended and the controls are showing up in the correct places.
We wanted to add a way to "tear off" pages so that the user can view our control in multiple windows. We achieved this by creating a new form with another ribbon. This "tear off form" is an empty form with a ribbon. When you "tear off," we create a new instance of the tear off form and move the custom control from the main to the tear off by saying " frmTearOff.Controls.add(custom_control); ". Again, so far so good. The ribbon in the tear off has basically the same functionality as the ribbon in the main and the PopupControlContainer tools are displaying the information correctly.
Here's where the problems start. When we close the tear off page, we wanted the custom control to go back into the main window. We achieved this by again, adding the control back to the main form. frmMain.Controls.add(custom_control); . The problem now is that the PopupControlContanier's do not show the correct controls. They do not show any controls at all (they are just blank drop downs). I forgot to mention that we also have a regular ControlContainer and that too does not display the control.
We thought that the problem had something to do with missing or corrupt references. First we tried resetting the references via PopupControlContainer.Control = null;...PopupControlContainer.Control = frmMain.getCustomControl(); and this worked...to an extent. When you select a tab, we reset the ribbon to have all the functionality of the correct control. We found if you left the selected tab on the guy that was torn off, this method fixed it. If you changed tabs, however, and went back to the old tab that had returned from a tear off window, the controls were again empty.
I've already stepped through in debug mode and checked to see if it was setting the controls correctly and if the listboxes were even still in the custom_control and I can't seem to find the problem. All hope is greatly appreciated.
Thanks.
---------
Edit - I feel as though I should add...When you flip back and forth between the tabs, I have the PopupControlContainers changing their "Control" to be the version of the custom_control in the selected tab. All the tabs load the PopupControlContainers properly except for the tab that was torn off via the method I explained before. The ribbon starts to get all glitchy when that tab is selected. It has trouble drawing itself. If you need more of an explanation let me know.
There might be problems in the toolbars manager caused by moving the controls between different Forms, but this is an issue that should be investigated by the support group. I would recommend submitting it to them with a sample which reproduces the issue: http://ko.infragistics.com/gethelp.
As a workaround to the issue, you can try to initialize a new custom control for the tear off with the data from the one on the main form. Use that new instance in the tear off Form and hide the control in the main Form and the PopupControlContainerTool in the ribbon. Then when the tear off closes, copy the data back to the main Form custom control and show them again.
I've done a little bit more fooling around and noticed that it has nothing to do with moving the controls between forms. I've made a very simple test program. The main form has only a ribbon and one custom control with two listboxes in it. One of those two listboxes is loaded into the PopupControlContainerTool in the ribbon. There's a button on the ribbon such that when you push it, a tearoff form with a ribbon comes up and loads that same listbox into its PopupControlContainerTool. Note that we are not moving the control between forms, we are only giving the tearoff a pointer to the listbox. Once the tearoff closes, the reference in the main formis lost and the pull down will no longer show the listbox.
Also, thanks Mike for the workaround idea. Unfortunately, for our purposes, simply copying the data back and forth may be a bit too much of a performance hit.
If you want me to attach the sample program let me know.
edit -
I've done an even more simple test. Main form has a ribbon and a listbox. The ribbon has a PopupControlContainerTool with the listbox set as its control. You push a button and launch a new "Tear-Off" form. In the constructor for the "Tear-Off", you pass a reference to the listbox in the main form. The constructor proceeds to use this reference for the "Tear-Off"'s ribbon's PopupControlContainer. This loads up okay. Now, if you close the "Tear-Off" form, the PopupControlContainer in the main form no longer has the control.
I think what is happening here is the list box is getting disposed when the tear off form gets closed. It is probably still in the Controls collection of the tear off form or one of the dock areas. Try to recursively walk down all Controls collections on the form and remove the list box before closing.