We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

NullReferenceException from BarManager

Has anybody ever met this exception? Any ideas of how to solve it? Thanks in advance. The detail message is as below: System.NullReferenceException: A BarItem (Text: ) that is not part of a BarManager is found in the menus or toolbars. Make sure to add the BarItem to a BarManager before adding it to the menus or toolbars. at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.RefreshContainer(IBarItemContainer container) at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.UpdateBarsInManager(BarManager manager) at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.UpdateBars() at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.OnFormActivated(Form form) at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.FormActivated(Object sender, EventArgs e) at System.Windows.Forms.Form.OnActivated(EventArgs e) at System.Windows.Forms.Form.set_Active(Boolean value) at System.Windows.Forms.Form.WmActivate(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

5 Replies

MJ Mano J Syncfusion Team November 17, 2005 03:55 PM UTC

Hi Andy, After looking into the exception, I have found that one of the barItem in your coding with no text is not added to MainFrameBarManager.Items collection. Please make sure that all the parentBarItems or BarItems that are created has to be added to MainFrameBarManager before adding into menus. this.MainFrameBarManager1.Items.AddRange(new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem[] { this.barItem1, this.barItem2, this.parentBarItem1, this.parentBarItem2, this.barItem3}); Please let me know if you have any questions. Regards, Mano


AD Administrator Syncfusion Team November 18, 2005 06:20 PM UTC

Mano, I got this exception too. Use your XPMenusMDI sample, add a button to the ImageEditorForm.cs and set the following code for the Click event: private void button10_Click(object sender, System.EventArgs e) { this.parentBarItem3.Items.Add( new BarItem( "Test" )); } Run the application, hit the button on the ImageEditorForm, switch to the TextEditorForm and then back to the ImageEditorForm. You''ll get the following exception. System.NullReferenceException: A BarItem (Text: Test) that is not part of a BarManager is found in the menus or toolbars. Make sure to add the BarItem to a BarManager before adding it to the menus or toolbars. at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.RefreshContainer(IBarItemContainer container) at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.UpdateBarsInManager(BarManager manager) at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.UpdateBars() at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.OnFormActivated(Form form) at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.set_LatestActiveMdiChild(Form value) at Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager.MdiChildActivated(Object sender, EventArgs e) This is because of the missing BarManager reference in the this.parentBarItem3.Items collection. Regards, Thomas >Hi Andy, > >After looking into the exception, I have found that one of the barItem in your coding with no text is not added to MainFrameBarManager.Items collection. > >Please make sure that all the parentBarItems or BarItems that are created has to be added to MainFrameBarManager before adding into menus. > >this.MainFrameBarManager1.Items.AddRange(new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem[] { this.barItem1, this.barItem2, this.parentBarItem1, this.parentBarItem2, this.barItem3}); > > >Please let me know if you have any questions. > >Regards, >Mano


MJ Mano J Syncfusion Team November 19, 2005 10:40 AM UTC

Hi Thomas, You should add all the barItems created programatically to the barManager and parentBarItem. You could also see this in the code generated by the designer while creating menus at design time. Please try changing the button_click code as follows and let me know if this works for you. Private BarItem bar22; private void btnbutton10_Click(object sender, System.EventArgs e) { //this.parentBarItem3.Items.Add( new BarItem( "Test" )); this.bar22 = new BarItem("Test"); this.childFrameBarManager1.Items.Add(this.bar22); this.parentBarItem3.Items.Add(this.bar22); } Regards, Mano


AD Administrator Syncfusion Team November 19, 2005 10:59 AM UTC

Hi Mano, Thanks for the reply. I''ve done a workaround with manually setting the BarManager reference to the ParentBarItem.Items.BarManager property. Why is this property null? It seams to me that the objects are not consistent. Regards, Thomas


EP Ebenezer P Syncfusion Team November 22, 2005 01:20 PM UTC

Hi Thomas, Sorry for the delay in responding. The MainFrameBarManager or ChildFrameBarManager should contain a reference to all the BarItems that you intend to use in an application. This BarManager manages the Form''s menus and tool bars and lets it participate in the user-customization feature. Therefore ParentBarItems or BarItems created programatically should be associated with the BarManager. Please let us know if you have any questions. Regards, Ebenezer P.

Loader.
Live Chat Icon For mobile
Up arrow icon