Checkbox in custom Ribbon

Started by Thomas Winkel, July 17, 2013, 10:20:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Thomas Winkel

Hi,

I made some modification to the following demo in order to replace the "Macro 2" button with a checkbox:
http://blog.bvisual.net/2011/03/14/how-to-run-vba-macros-from-a-ribbon-button-in-visio-2010/

I would like to use the "getPressed" callback to initialize the checkbox on startup:
getPressed="Checkbox_getPressed"
But Checkbox_getPressed is never called (see attached example).

Any ideas?

Regards,
Thomas

Thomas Winkel

In the attached document I stripped the code down to a minimum.
Also I included a getLabel callback.

As far as I understand, getLabel and getPressed should be executed whenever I call objRibbon.Invalidate.
But they are not.
The only result is that the checkbox value is set to false.
onAction and onLoad are working fine.

Similar code in Excel works proper:
http://www.office-loesung.de/ftopic245891_0_0_asc.php

Any ideas?
Has someone a working example of a checkbox or togglebutton?


Thomas Winkel

Thanks, David.
Really sad, that Visio still behaves so different to other Office products...
The method, described in your link would be OK for me.
But unfortunately there is no "pressed" attribute defined, as it is for other callbacks (getLabel => label).

Sarang

If you are trying for checkbox, there is "getPressed" available

whereas on Ribbon.Invalidate("chkbox_name") will execute the method written on "getPressed"

you can return true/false from this method depending on some flags (you need to set these as per the req - true/false)... return true will set chk box value to true and return false will set it to false.

I have used checkbox & it works fine for me, there is a possibility that your case might be different.
Regards,
Sarang

Thomas Winkel

#5
Thanks, Sarang.
What you describe is exactly what I have done. Please have a look at my attached examples above.
Ribbon.Invalidate sets all checkboxes to zero, Ribbon.InvalidateControl("chkbox_name") sets only chkbox_name to zero and Ribbon.Invalidate("chkbox_name") is not valid code.
The existing getPressed method would return a boolean value, but is never called.
Similar code in Excel does the job correctly.
As I generate the ribbon xml via VBA in runtime anyhow, it would be possible to initialize the checkboxes by generating custom xml code.
But unfortunately there is nothing like a "pressed" attribute available. Only the getPressed callback.
For a label you have the choice between a static one via label="Text" property or a dynamic one via getLabel="getLabel" callback.

The problem is only related to Visio VBA. In VB .NET it should work.
If you really have a working example in Visio VBA it would be great if you could post a demo.

Sarang

Hey Thomas,

Sorry, I didn't noticed that it's for VBA. I was suggesting it for C#. As you mentioned, it will work for VB.net - it works for C# as well.
Hope you found the solution for same in VBA.

Good luck!
Regards,
Sarang

AndyW

Your getPressed method is wrong, it should look like this,

Public Function Checkbox_getPressed(control As IRibbonControl) As Boolean
Live life with an open mind

Thomas Winkel

Andy, you are the master! Thanks.

Strange that the Visio code is different to Excel code...