Print Page | Close Window

Trying to delete a popup menu

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=12539
Printed Date: 07 October 2024 at 10:30am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Trying to delete a popup menu
Posted By: MadRiver
Subject: Trying to delete a popup menu
Date Posted: 27 October 2008 at 9:46am
Hello,

My application allows users to add and remove menu items via scripting. When all the menu items are removed from a particular menu, I would like to remove the menu.

Currently, I try to a find a menu item by ID, confirm that it is CommandBarButton, then delete it:
pControl->Delete();

Before deleting, I get the control's parent:
ICommandBar * pParent = pControl->GetParent();
// xtpBarTypePopup == pParent->GetType();
long cnt = pParent->GetControls()->GetCount();
if (0 == cnt) {
    pParent->Delete();
}
This call to Delete() crashes.
What am I doing wrong?
Thanks for any insight...




Replies:
Posted By: Oleg
Date Posted: 27 October 2008 at 10:49am
Hi,
 
pParent is PopupBar of Control. You need Delete not PopupBar but Control that has this Popupbar as Child CommandBar. so Find it and remove.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: MadRiver
Date Posted: 29 October 2008 at 3:22pm
Thanks for the reply.
I am able to delete the menu if it is only one level deep, but I'm not sure I have the most efficient approach.
When I find the menuItem to remove, I get its parent, a CommandBarPopup control. Do I have to traverse all the controls in the top-level CommandBar, looking for the Control with the matching CommandBar?

I also need to handle hierarchical menus, and I am having trouble traveling up the hierarchy.


For example:
TopLevel
----Level1
--------Level2
------------MenuItem1

When I delete MenuItem1, I want to see if its 'parent' (Level2) is empty, and delete it if it is. Similarly, I want to get Level2's parent, and delete it if it is empty, and so on.
Is there a straightforward way to do this?   



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net