Visio Guy

Visio Discussions => Programming & Code => Topic started by: Thomas Winkel on July 17, 2013, 10:20:23 PM

Title: Checkbox in custom Ribbon
Post by: Thomas Winkel on July 17, 2013, 10:20:23 PM
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
Title: Re: Checkbox in custom Ribbon
Post by: Thomas Winkel on July 21, 2013, 09:21:25 AM
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?
Title: Re: Checkbox in custom Ribbon
Post by: bVisual on July 23, 2013, 03:07:05 PM
Hmmm, the following thread is not filling me with great hope : http://social.microsoft.com/Forums/ar-SA/988b3569-8519-4253-b8a9-222740c473d8/problems-with-vba-ribbon-customization-in-project-2010-pro (http://social.microsoft.com/Forums/ar-SA/988b3569-8519-4253-b8a9-222740c473d8/problems-with-vba-ribbon-customization-in-project-2010-pro)
Title: Re: Checkbox in custom Ribbon
Post by: Thomas Winkel on July 23, 2013, 09:07:53 PM
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).
Title: Re: Checkbox in custom Ribbon
Post by: Sarang on July 24, 2013, 01:58:12 PM
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.
Title: Re: Checkbox in custom Ribbon
Post by: Thomas Winkel on July 24, 2013, 07:21:13 PM
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.
Title: Re: Checkbox in custom Ribbon
Post by: Sarang on July 25, 2013, 10:37:58 AM
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!
Title: Re: Checkbox in custom Ribbon
Post by: AndyW on July 26, 2013, 07:29:07 AM
Your getPressed method is wrong, it should look like this,

Public Function Checkbox_getPressed(control As IRibbonControl) As Boolean
Title: Re: Checkbox in custom Ribbon
Post by: Thomas Winkel on July 26, 2013, 09:45:22 PM
Andy, you are the master! Thanks.

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