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~