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.

Dynamically adding menu items to a merged menu

Thread ID:

Created:

Updated:

Platform:

Replies:

53083 Dec 7,2006 03:28 PM Jan 12,2007 06:07 PM Windows Forms 10
loading
Tags: Tools
Administrator [Syncfusion]
Asked On December 7, 2006 03:28 PM

How to correctly add a menu item to a merged menu? I'm doing it the following way (see below) but, apparently, it results in two similar menu items being added. It used to work fine in v 4.1

Attached is an example demonstrating the problem (click on "View->New", then on "Add Menu Item")

private static BarItem FindByText(IList items, string text)
{
foreach (BarItem b in items)
{
// ignore the "&" symbol
if (b.Text.Replace("&", "") == text.Replace("&", "")) return b;
}
return null;
}

private void barItem2_Click(object sender, EventArgs e)
{
Bar mergedMainMenu = mainMenu.Manager.GetMergedEquivalent(mainMenu, mainMenu);
ParentBarItem pbi = (ParentBarItem)FindByText(mergedMainMenu.Items, "View");
BarItem item = new BarItem("foo");
pbi.Manager.Items.Add(item);
pbi.Items.Add(item);
}


ClosingFloatingWindow1.zip

Administrator [Syncfusion]
Replied On December 7, 2006 03:32 PM

By the way, there is one more very irritating thing: if you have several toolbars on your form (SdiForm in my case), their designer-time positions do not get persisted. Every time we open it in form designer, they are positioned in the top-left corner of the _screen_ on top of each other. Of course this is not critical since those positions play no role in runtime, just thought I'd let you know about it.

Gopalakrishnan S [Syncfusion]
Replied On December 7, 2006 08:42 PM

Hi Andrew,

We really regret for the inconvenience caused. We were able to see the issue. We are currently working on this issue. We will update the details on Monday.

Thank you using Syncfusion products.

Regards,
S.Gopal.

Gopalakrishnan S [Syncfusion]
Replied On December 11, 2006 08:51 PM

Hi Andrew,
Sorry for the getting back to you. I have tried a workaround for this.However,that has not worked successfully.I am still looking into the source to find some other way to help you out. Meanwhile I will go ahead and log a bug report so that we can address this issue at the earliest.

Here is the code snippet :

this.mainFrameBarManager1.UnregisterMdiChildTypes(new Type[] { typeof(SdiForm) });
Bar mergedMainMenu = mainMenu.Manager.GetMergedEquivalent(mainMenu, mainMenu);
ParentBarItem pbi = (ParentBarItem)FindByText(mergedMainMenu.Items, "View");
BarItem item = new BarItem("foo");
pbi.Manager.Items.Add(item);
pbi.Items.Add(item);
mainFrameBarManager1.RegisterMdiChildTypes(new Type[] { typeof(SdiForm) });

Best Regards,
S.Gopal.

Gopalakrishnan S [Syncfusion]
Replied On December 22, 2006 11:48 AM

Hi Andrew,

We regret for the inconvenience caused. I have logged a bug report # 3225 regarding this issue. Please track the status of this bug in the link below.

Defect #3225 - When adding a barItem in MergedMenu two baritems added.


We will fix this issue at the earliest and keep you informed.

Thanks for bringing this issue to our attention.

Regards,
S.Gopal.

Administrator [Syncfusion]
Replied On January 5, 2007 12:37 PM

Hi guys,

Do you plan to fix this bug any time soon? We have an upcoming release...

Regards,
Andrew

Gopalakrishnan S [Syncfusion]
Replied On January 5, 2007 01:47 PM

Hi Andrew,

We are currently working on this issue. We have increased the priority of the defect. We will update the time frame needed to fix the issue after consulting with the development team.

Thanks,
S.Gopal.

Gopalakrishnan S [Syncfusion]
Replied On January 11, 2007 07:34 PM

Hi Andrew,

I am sorry for the wrong information displayed. Please use the following code snippet:

ParentBarItem pbi = (ParentBarItem)FindByText(mergedMainMenu.Manager.Items, "View");

instead of,

ParentBarItem pbi = (ParentBarItem)FindByText(mergedMainMenu.Items, "View");

Please let me know if this works.

Thanks,
S.Gopal.

Administrator [Syncfusion]
Replied On January 12, 2007 12:49 PM

Hi S.Gopal,

First of all, thank you for your support!

The approach that you suggested worked on the submitted example; however, it might work incorrectly if there are menu items with the same name in other menu branches. The reason for that is that

mergedMainMenu.Items returns a collection of menu items located directly under mergedMainMenu (there are 3 of them in the example);
mergedMainMenu.Manager.Items returns a collection of menu items managed by the Manager (there are 7 of them in the example).

It looks like this example works fine whithout a call to GetMergedEquivalent, but will it work in more complex scenarios?

private void barItem2_Click(object sender, EventArgs e)
{
ParentBarItem pbi = (ParentBarItem)FindByText(mainMenu.Items, "View");
BarItem item = new BarItem("foo");
pbi.Manager.Items.Add(item);
pbi.Items.Add(item);
}

Thanks!
Andrew

Administrator [Syncfusion]
Replied On January 12, 2007 12:56 PM

>It looks like this example works fine whithout a call to GetMergedEquivalent, but will it work in more complex scenarios?

Opps of course it won't work if the parent bar item comes from an SDI form :(

Gopalakrishnan S [Syncfusion]
Replied On January 12, 2007 06:07 PM

Hi Andrew,

Currently,our developer is working on this and we will be addressing this issue at the earliest.

Thanks for your patience.

Best Regards,
S.Gopal.

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.

;