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.

Why there is no PopupMenu.AfterPopup method?

Thread ID:

Created:

Updated:

Platform:

Replies:

51284 Nov 1,2006 06:52 PM Nov 2,2006 07:46 PM Windows Forms 5
loading
Tags: Tools
Administrator [Syncfusion]
Asked On November 1, 2006 06:52 PM

I'm adding some menu items to the existing popup menu in BeforePopup event handler and I want to remove them when the popup menu is closed, but there is no AfterPopup event. Can you suggest a workaround to this problem?

Maybe I'm doing the wrong thing? Basically, we have hundreds of so-called "actions". When user right-clicks on a grid, each action has a chance to add menu items to the popup menu, depending on a context. Since I don't want to recreate popup menu on every right click, I decided to dynamically add and remove those menu items (which is quite painful, btw). Is there a better approach?

Thanks!
Andrew

Administrator [Syncfusion]
Replied On November 2, 2006 04:02 PM

Hi Andrew,

The PopupMenu does not have "AfterPopup" or any other similar Events. But the ParentBarItem has "PopupClosed" Event which can be used to remove the Items from the PopupMenu.

Add new BarItems to the PopupMenu in the PopupMenu's "BeforePopup" event and remove those items in the PopupMenu's ParentBarItem "Popupclosed" event. Here is the code snippet for doing the same.

BarItem b1 = new BarItem();

void popupMenu1_BeforePopup(object sender, Syncfusion.Windows.Forms.CancelMouseEventArgs e)
{
if (popupMenu1.GetPopupParentControl() == gradientPanel2)
{
b1.Text = "Newly Added";
b1.ID = "New";
parentBarItem1.Items.Add(b1);
}
}

private void parentBarItem1_PopupClosed(object sender, EventArgs e)
{
parentBarItem1.Items.Remove(b1);
}

I have attached a sample. Hope this is what you actually needed.
PopupEvents.zip

Best Regards,
Purusothaman.R

Administrator [Syncfusion]
Replied On November 2, 2006 05:06 PM

Yes, this is what I initially did but the PopupClosed event wasn't coming:

menu.BeforePopup = delegate { AddMenus(); } // works
menu.ParentBarItem.PopupClosed = delegate { RemoveMenues(); } // never got there

Oh probably the problem is that this popup menu is a merged popup menu... I'll try it.

Oops menu.ParentBarItem.Manager == null, is this by design?

Administrator [Syncfusion]
Replied On November 2, 2006 07:27 PM

I tried this again and now I'm getting the PopupClosed event... must have been some silly mistake. Sorry!

Purusothaman R [Syncfusion]
Replied On November 2, 2006 07:43 PM

Hi Andrew,

PopupMenus can be used in two ways. The first one is by using the default ParentBarItem and by using a MainFrameBarManager.

If the "default ParentBarItem" is used, the PopupMenu.ParentBarItem.Manager will be null. It is by design. When using the later method, the MainFrameBarManager can be assigned to the ParentBarItem.Manager.

Which method do you use? Could you please send us a sample to show your actual need?

Thanks,
Purusothaman.R

Administrator [Syncfusion]
Replied On November 2, 2006 07:46 PM

Hi Andrew,

Thanks for your update.

Ignore my previous update if the issue is solved.

Thanks,
Purusothaman.R

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.

;