PC Review


Reply
Thread Tools Rate Thread

How to delete the controls in a CommandBarPopup?

 
 
Teodora Gancheva
Guest
Posts: n/a
 
      12th Oct 2009
Hi,
I am developing a C# COM add-in for MS Office 2003 and 2007. My add-in
creates a custom command bar with a CommandBarPopup menu containing several
CommandBarPopup submenus populated with CommandBarButton objects. Upon user
click on some buttons, I'd like to perform 'refresh' on the submenus i.e.
delete the buttons and re-create them.
I am doing so using the following code:
for (int index = 1; index <= popup.Controls.Count; index++)
{
popup.Controls[index].Delete(1);
index--;
}
This works for all buttons except the one that was actually clicked, for it
a COMException with message "Error HRESULT E_FAIL has been returned from a
call to a COM component" is thrown. Am I not allowed to delete this button
because it has just been clicked, and what other options do I have - delete
the whole popup?
Thanks for all advice,
Teodora Gancheva
 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      12th Oct 2009
It would be logical that you couldn't delete a button during its Click()
event. Think about it.

If you really want to do what you're doing then set a timer in the Click()
event that will fire after that event is completed, then do your refresh in
the timer event handler. Just make sure the timer thread is the same or
marshalled to the main thread.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Teodora Gancheva" <(E-Mail Removed)> wrote in
message news:8E56D3D7-C998-4A46-AEF2-(E-Mail Removed)...
> Hi,
> I am developing a C# COM add-in for MS Office 2003 and 2007. My add-in
> creates a custom command bar with a CommandBarPopup menu containing
> several
> CommandBarPopup submenus populated with CommandBarButton objects. Upon
> user
> click on some buttons, I'd like to perform 'refresh' on the submenus i.e.
> delete the buttons and re-create them.
> I am doing so using the following code:
> for (int index = 1; index <= popup.Controls.Count; index++)
> {
> popup.Controls[index].Delete(1);
> index--;
> }
> This works for all buttons except the one that was actually clicked, for
> it
> a COMException with message "Error HRESULT E_FAIL has been returned from a
> call to a COM component" is thrown. Am I not allowed to delete this button
> because it has just been clicked, and what other options do I have -
> delete
> the whole popup?
> Thanks for all advice,
> Teodora Gancheva


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CommandBarPopup event? =?Utf-8?B?Um9iZXJ0IEcuIFNjaGFmZnJhdGg=?= Microsoft Outlook Program Addins 1 8th Oct 2007 04:21 PM
The "temporary" parameter of CommandBarPopup.Controls.Add Tom Microsoft Excel Programming 1 17th Aug 2007 01:36 PM
Delete controls that are initialized but not added to other controls. zlf Microsoft Dot NET Framework Forms 1 15th Jul 2007 04:08 PM
load CommandBarPopup Jim Microsoft Outlook Program Addins 0 15th Feb 2006 06:13 PM
focus on commandbarPopup vivek Microsoft Excel Programming 0 12th Jan 2004 07:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:20 PM.