The ribbon items are not updated

Add-in Express™ Support Service
That's what is more important than anything else

The ribbon items are not updated
 
chipbk10


Guest


What I am trying to do is to catch all shapes events by using this tutorial: https://www.add-in-express.com/creating-addins-blog/2012/02/21/excel-shapes-events/#selection

When a single shape gets selected, a ribbon button is enabled. In opposite, when there is no single shape selection (no selection or multiple selections), the ribbon button is disabled.

My code is as follow:

private void ShapesSelectionChange(MyShapes newlySelectedShapes, MyShapes deselectedShapes)
{
MyShape iShape = null;

//- if single selection
if (shapesSelectedNow.Count == 1) {

iShape = shapesSelectedNow[0];
}

//- if not single selection, iShape = null
//- enable the ribbon button, based on the single selection value.
//- Put the breakpoint here, it works perfectly.

ADXRibbonGroup group = adxRibbonTab1.Controls[0].AsRibbonGroup;
ADXRibbonGallery gallery = group.Controls[2].AsRibbonGallery;

bool b = (iShape != null);
gallery.Enabled = b;

Log.Output("ShapesSelectionChange. selected: " + newlySelectedShapes.Count.ToString() + "; deselected: " + deselectedShapes.Count.ToString() + "; total selected: " + shapesSelectedNow.Count.ToString() + ".");

}

With the above code, the ribbon button (or gallery) works incorrectly. More details as follow:

- the button gets enabled when we click on blank
- the button gets disabled when a single shape gets selected.

However, if we put the breakpoint in the above function, it works correctly.

It means the ribbon items are not updated after the single selected is detected. I share my code, in the case you can help:

https://www.dropbox.com/sh/ri9csd8ozfjvwfz/AACFtf9ve5SMHGSkvDlHDaeoa?dl=0
Posted 22 Dec, 2014 04:40:19 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Hieu,

The original project doesn't produce this issue. That is, something related to your project causes it. I suggest that you debug your project. You can add a number of debug messages to your code; use System.Diagnostics.Debug.WriteLine(). You collect the messages at run time using DebugView (see http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx).


Andrei Smolin
Add-in Express Team Leader
Posted 22 Dec, 2014 05:14:53 Top
chipbk10


Guest


The original project can produce this issue. If you convert your original project to apply for PowerPoint.
I've converted your project to apply for PowerPoint. The same code with all events. You can test it here : https://www.dropbox.com/sh/62c0ebqip5vrhuw/AAC3OQvkSqWTKa_7iOjczNOva?dl=0

Thanks,
Posted 22 Dec, 2014 10:38:41 Top
chipbk10


Guest


I use SendMessage and I fix this issue.

public const int WM_USER = 0x0400;
public const int MESSAGE_UPDATE_RIBBON = WM_USER + 1000;

private void ShapesSelectionChange(MyShapes newlySelectedShapes, MyShapes deselectedShapes)
{
SendMessage(MESSAGE_UPDATE_RIBBON);

Log.Output("ShapesSelectionChange. selected: " + newlySelectedShapes.Count.ToString() + "; deselected: " + deselectedShapes.Count.ToString() + "; total selected: " + shapesSelectedNow.Count.ToString() + ".");
}

private void AddinModule_OnSendMessage(object sender, ADXSendMessageEventArgs e)
{
if (e.Message == MESSAGE_UPDATE_RIBBON)
{
isWorking = false;

MyShape shape = null;

if (shapesSelectedNow.Count == 1)
{
shape = shapesExistingNow[0];
}

bool b = (shape != null);
RibbonButton.Enabled = b;

isWorking = true;
}
}

Thanks for your patience. I still have a question. In the AddinModule_OnSendMessage function, do I need to stop the commandBarUpdate by assigning the value of the variable isWorking. (e.g, isWorking = false; .... isWorking = true) ?
Posted 22 Dec, 2014 11:31:16 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Hieu,

Great.

chipbk10 writes:
In the AddinModule_OnSendMessage function, do I need to stop the commandBarUpdate by assigning the value of the variable isWorking. (e.g, isWorking = false; .... isWorking = true) ?


As far as I remember, that variable is used to avoid handling the CommandBarUpdate event when handling it is unnecessary. I believe you know that code far better than me ))


Andrei Smolin
Add-in Express Team Leader
Posted 23 Dec, 2014 07:06:46 Top