Hi,
how do you programtically click a button on a Toolbar ?
Thanks
Michael
I think the best thing to do here would be to separate out the click event handler code for this one tool into its own method which is called from the normal ToolClick event handler. Then you can call that method from anywhere else in your code and simulate the button's click action without having to interact with the toolbars manager.
could you please describe how? I am not sure I understand the solution.
Best regards,
You can try that, but I believe the event will only be fired if that specific instance of the tool is clicked. Also, if you are programmatically adding the tool to a toolbar, menu, or ribbon group after EndInit() has been called on the toolbars manager in the designer code, the tools will be cloned anyway, so you would be hooking the event on a tool that wasn't actually added. After the toolbars manager is initialized, you should call Tools.AddTool() and pass in the key of the tool you want to add. Get the return value and hook any events on that tool, which is the tool that was actually added to the container.
I have changed you code slightly to create and add the root tool and then add an instance of that tool to the first toolbar in the toolbars manager:
Infragistics.Win.UltraWinToolbars.ButtonTool btnCheckRootTool = new Infragistics.Win.UltraWinToolbars.ButtonTool("Press"); this.ultraToolbarsManager1.Tools.Add(btnCheckRootTool);
Infragistics.Win.UltraWinToolbars.ButtonTool btnCheckInstanceTool = (Infragistics.Win.UltraWinToolbars.ButtonTool)this.ultraToolbarsManager1.Toolbars[0].Tools.AddTool("Press");btnCheckInstanceTool.ToolClick+=new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(btnCheck_ToolClick);
private void btnCheckInstanceTool_ToolClick(object sender, ToolClickEventArgs e) {
}
Well you will probably want to change the value passed to the indexer of the Toolbars collection from 0 to a string with the key of your toolbar. Is that where you received the exception?