Hi,
As per the topic, how can I programmatically clear all controls including the keys of the tabs, and the controls within these tabs, such as button tools?
I tried doing a tabs.Clear(), but when I re-add the buttontools, I get an error saying that the keys already exist
I am also trying to do this on my ribbon that I build in code. My logic builds the ribbon tabs (per user )from info in the database. When one user logs off, I want to clear the ribbon menu tools that I have added in my logic. I tried to use the tools.clear(), but it also cleared the tools that were created in designer. Is this the way it is supposed to work?
I also tried RESETSTATE, and it didn't seem to do anything.
Can someone tell me what I am doing wrong?
KDuaneS,
Clearing the UltraToolbarsManager's root Tools collection will clear all of the components tools. It does not matter if they were created at design time or at run time. In order to clear only certain tools, you will need to use code similar to:
foreach (RibbonTab tab in this.ultraToolbarsManager1.Ribbon.Tabs) { foreach (RibbonGroup group in tab.Groups) { for (int i = group.Tools.Count - 1; i >= 0; i--) { ToolBase tool = group.Tools[i]; group.Tools.Remove(tool); this.ultraToolbarsManager1.Tools.Remove(tool); } tab.Groups.Remove(group); } }
The above code loops through all of the tools in the RibbonGroups, removes them from the group, and then removes them from the root Tools collection. This will ensure that only some tools are removed instead of all of them. If you want to remove tools from different parts of the ribbon you can do that too; you just have to remember to remove the instance and then remove the tool from the root Tools collection.
~Kim~
Duane,
Each instance of a Tool will have a property called OwnerIsApplicationMenuArea, which, when it is placed in the ApplicationMenu, will return true. This will return true for all tools in teh ApplicationMenu, regardless of if it is in ToolAreaLeft of ToolAreaRight. You could also set the Tag property of the Tools you put in the ToolAreaLeft, essentially using that as a flag that indicates that those Tools are in the ApplicationMenu's ToolAreaLeft.
Hope this helps,
Kim,
Thanks for the code.
I am also adding a few tools to the Ribbon.ApplicationMenu.ToolAreaLeft. I would like to remove those tools when a user signs out of my application. Is there a way to mark or flag the ones that were added to the tools when the user signed into my app? I could remove them by name, but I am trying not to use the specific name, to ease future maintenance.
duane