Hi ,
I am trying to add buttons to the Ribbon's app menu in the Right Tool Area. Basically, I need to populate it with my Most Recently Used Files List. When I add buttons there through the designer, it works fine. But when I add tools at run time (coded below), it does appear on the ribbon, but my app crashes when I click on any one of them.
Basically what I did was:
List<string> RecentFilesList =GetRecentFilesList();
ButtonTool buttonTool = null; foreach (string sProjpath in RecentFilesList) { string sKey = sProjpath; buttonTool = new ButtonTool(sKey);
if (ToolbarManager.Tools.Exists(sKey)) continue;
buttonTool.SharedPropsInternal.Caption = sProjpath;
ToolbarManager.Tools.AddRange(new ToolBase[] { buttonTool });
//Add the button to the right area of the application menu buttonTool = new ButtonTool(sKey);
ToolbarManager.Ribbon.ApplicationMenu.ToolAreaRight.NonInheritedTools.AddRange(new ToolBase[] { buttonTool });
ToolbarManager.Ribbon.ToolbarsManager.Tools[sKey].SharedProps.Enabled = true;
}
At Run Time I do get to see my recent files buttons displayed on the right side of the app menu. But when I click on them, my application crashes. The exception and the stack trace is :
System.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Win.UltraWinToolbars.ToolBase.OnToolClick() at Infragistics.Win.UltraWinToolbars.ToolMenuItem.OnClick() at Infragistics.Win.UltraWinToolbars.PopupMenuItemUIElement.DoClickProcessing(MouseEventArgs e) at Infragistics.Win.UltraWinToolbars.PopupMenuItemUIElement.OnMouseUp(MouseEventArgs e) at Infragistics.Win.UIElement.OnMouseUp(MouseEventArgs e) at Infragistics.Win.TextUIElementBase.OnMouseUp(MouseEventArgs e) at Infragistics.Win.ControlUIElementBase.ProcessMouseUpHelper(Object sender, MouseEventArgs e) at Infragistics.Win.ControlUIElementBase.ProcessMouseUp(Object sender, MouseEventArgs e) at Infragistics.Win.Utilities.ProcessEvent(Control control, ProcessEvent eventToProcess, EventArgs e) at Infragistics.Win.UltraControlBase.OnMouseUp(MouseEventArgs e) at Infragistics.Win.UltraWinToolbars.PopupControlBase.OnMouseUp(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at PSES.Program.Main(String[] args) in D:\CCRC_View\E413496_CCRC_view\Prod_URT\ProfitSuiteEngineeringStudio\Infrastructure\PSES\Program.cs:line 26 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
Am I missing some additional step. I ensured that I am not missing any step done at compile time in the designer.
Can anyone help.
Regards
Roshan
Hello Roshan,
I was not able to reproduce your scenario. The sample I created trying to reproduce the desired behavior by you seems to work fine to me. Please review it and feel free to let me know if something comes up.
One more input:
The tool click event has been handled, and debugger hits there when buttons are added at compile time.
Regards, Roshan