Invalid CommandBar button reference, Need Workaround for KB 230876

A

A Johnson

I'm developing several office addin applications with VS
2003 in C#, primarily for Word, and have run into the
issue outlined in the Knowledge Base article 230876.

I'm trying to Enable/Disabling several buttons in my
custom menu and toolbar during the application life cycle
but after several documents are opened and closed I
receive error when referencing the button object, Invalid
object.

I catch the error and use the suggested FindControl()
(tried using the CommandBar.Controls[] collection as well)
to get another reference to the object. This works but
then the event hander stops and the buttons no longer
respond to user interaction. If I re-register the Click
event (remove then add), the next time the user clicks I
get 2 events.

I'd appreciate any insight into a workaround to this known
issue in the office applications. I have sample code if
needed.

Thanks,
Al
 
L

Linas Mikutaitis

Hi,

I have the same problem with Word 2k. Have you found any workaround or
solution?

Thanks,
LM
 
A

A Johnson

No resolution yet. I've moved on for now but will need to
address it soon. My next step is to use a support
incident and see what MS has to say. If I get a
resolution I'll post back.

Al
-----Original Message-----
Hi,

I have the same problem with Word 2k. Have you found any workaround or
solution?

Thanks,
LM


I'm developing several office addin applications with VS
2003 in C#, primarily for Word, and have run into the
issue outlined in the Knowledge Base article 230876.

I'm trying to Enable/Disabling several buttons in my
custom menu and toolbar during the application life cycle
but after several documents are opened and closed I
receive error when referencing the button object, Invalid
object.

I catch the error and use the suggested FindControl()
(tried using the CommandBar.Controls[] collection as well)
to get another reference to the object. This works but
then the event hander stops and the buttons no longer
respond to user interaction. If I re-register the Click
event (remove then add), the next time the user clicks I
get 2 events.

I'd appreciate any insight into a workaround to this known
issue in the office applications. I have sample code if
needed.

Thanks,
Al


.
 
A

AlfontzCel

I have a resolution to this issues as suggested by MS Support
Use the CommandBar.FindControl method to get a temp object every time you need access to the button. It’s fairly fast and I’ve noticed only a small performance hit. Note don’t use the CommandBars.FindControl, call the method associated with the toolbar you want.
Psudo code
public bool Enable

se

cbb = CommandBars[“MyToolbarâ€].FindControl(…,“MyButtonTagâ€,…)
cbb.Enabled = value



Also I’m working with C# and I needed to cache the CommandBarControl object returned from the Add method and never reassign it. Otherwise the GC will release the object along with the Click event registration


----- Linas Mikutaitis wrote: ----

Hi

I have the same problem with Word 2k. Have you found any workaround o
solution

Thanks
L


A Johnson said:
I'm developing several office addin applications with V
2003 in C#, primarily for Word, and have run into th
issue outlined in the Knowledge Base article 230876
I'm trying to Enable/Disabling several buttons in m
custom menu and toolbar during the application life cycl
but after several documents are opened and closed
receive error when referencing the button object, Invali
object
I catch the error and use the suggested FindControl(
(tried using the CommandBar.Controls[] collection as well
to get another reference to the object. This works bu
then the event hander stops and the buttons no longe
respond to user interaction. If I re-register the Clic
event (remove then add), the next time the user clicks
get 2 events
I'd appreciate any insight into a workaround to this know
issue in the office applications. I have sample code i
needed
A
 
L

Linas Mikutaitis

Thanks a lot! It really did help.


AlfontzCel@REMOVE_THIS.comcast.net said:
I have a resolution to this issues as suggested by MS Support.
Use the CommandBar.FindControl method to get a temp object every time you
need access to the button. It's fairly fast and I've noticed only a small
performance hit. Note don't use the CommandBars.FindControl, call the
method associated with the toolbar you want.
Psudo code:
public bool Enabled
{
set
{
cbb = CommandBars["MyToolbar"].FindControl(.,"MyButtonTag",.);
cbb.Enabled = value;
}
}

Also I'm working with C# and I needed to cache the CommandBarControl
object returned from the Add method and never reassign it. Otherwise the GC
will release the object along with the Click event registration.
----- Linas Mikutaitis wrote: -----

Hi,

I have the same problem with Word 2k. Have you found any workaround or
solution?

Thanks,
LM


A Johnson said:
I'm developing several office addin applications with VS
2003 in C#, primarily for Word, and have run into the
issue outlined in the Knowledge Base article 230876.
I'm trying to Enable/Disabling several buttons in my
custom menu and toolbar during the application life cycle
but after several documents are opened and closed I
receive error when referencing the button object, Invalid
object.
I catch the error and use the suggested FindControl()
(tried using the CommandBar.Controls[] collection as well)
to get another reference to the object. This works but
then the event hander stops and the buttons no longer
respond to user interaction. If I re-register the Click
event (remove then add), the next time the user clicks I
get 2 events.
I'd appreciate any insight into a workaround to this known
issue in the office applications. I have sample code if
needed.
Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top