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.
Unfortunately, activation email could not send to your email. Please try again.

NullReferenceException from BarManager

Thread ID:

Created:

Updated:

Platform:

Replies:

37196 Nov 17,2005 05:00 AM Nov 22,2005 08:20 AM General Discussion 5
loading
Tags: General Discussion
Andy Wu
Asked On November 17, 2005 05:00 AM

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)

Mano J [Syncfusion]
Replied On November 17, 2005 10:55 AM

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

Administrator [Syncfusion]
Replied On November 18, 2005 01:20 PM

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

Mano J [Syncfusion]
Replied On November 19, 2005 05:40 AM

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

Administrator [Syncfusion]
Replied On November 19, 2005 05:59 AM

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

Ebenezer P [Syncfusion]
Replied On November 22, 2005 08:20 AM

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;