Select Case does not seem to work for buttons

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

Select Case does not seem to work for buttons
 
Leon Lai Kan




Posts: 200
Joined: 2018-12-20
Hi, Andrei

I am trying to use sender in my Excel add-in

I created a Drop Down (Add Drop Down)
Then I added a few buttons in the Drop Down

Step 1
I use If Sender in my codes:

 Private Sub Button19_5X_OnClick(ByVal sender As System.Object, _
          ByVal control As AddinExpress.MSO.IRibbonControl, _
          ByVal pressed As System.Boolean) _
          Handles Button19_5A.OnClick, Button19_5B.OnClick, Button19_5C.OnClick
.
.
If sender Is Button19_5A Then MsgBox(" 19_5A")
If sender Is Button19_5B Then MsgBox(" 19_5B")
If sender Is Button19_5C Then MsgBox(" 19_5C")

End Sub


This code works correctly.

Step 2

I try to do the same thing using Select Case instead of If


Select Case sender

      Case Button19_5A         '// ERROR HERE
           MsgBox(" 19_5A")    


      Case Button19_5B         '// ERROR HERE
           MsgBox(" 19_5B")     

      Case Button19_5C         '// ERROR HERE
            MsgBox(" 19_5C")      

End Select




The Error Message is:

Operator "=" is not defined for types 'Object' and AddinExpress.MSO.ADXRibbonButton


What is wrong with my code?

ADDED

I searched the web, but the only found this example which works. It seems strange.The author himself admits it was used with VB6, and no longer used with VB.NET


Select Case True
     Case sender Is Button19_5A
       MsgBox(" 19_5A")

     Case sender Is Button19_5B
       MsgBox(" 19_5B")

     Case sender Is Button19_5C
       MsgBox(" 19_5C")
End Select







------
I have a 2nd question:

The Drop Down arrow is inside a large empty box.
When we select any button, I was expecting (because there is a box waiting to be filled)
that the name of the selected button would be displayed in the Box.

But this not not happen. The Box remains empty.

Is this the normal behaviour?
Can we make the selected item appear in the box?


Thanks
Leon
Posted 26 Apr, 2019 09:02:52 Top
Andrei Smolin


Add-in Express team


Posts: 17115
Joined: 2006-05-11
Hello Leon,

I assume #1 is an issue in VB.NET. In the IF version of your logic, the IS operator performs the check, while in the SELECT CASE version VB.NET doesn't let you compare two objects of different types (do you use Option Strict ON?).

#2. You are responsible for modifying Ribbon controls that you create. The Office Ribbon provides very little service.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Apr, 2019 06:51:17 Top
Leon Lai Kan




Posts: 200
Joined: 2018-12-20
Hi, Andrei

Thanks for your reply.

Concerning your answer to question #2.
Do you mean it is the normal behaviour of Drop Down in Add-In Express NOT to indicate the selected item in the box, and that we need to do some programming to achieve the desired behaviour?

If this is so, it is very unfortunate. Can you give me some indication how I can cause the selected item to appear in the Drop Down box?

I have searched the ADX Manual, and also the ADX Forum, but have not seen anything.

Best Regards,
Leon
Posted 29 Apr, 2019 07:51:23 Top
Andrei Smolin


Add-in Express team


Posts: 17115
Joined: 2006-05-11
Leon,

I may misunderstand you. In terms of selected item, a Ribbon dropdown does reflect the selection: if you select an item, the dropdown does show it.

If in your case the drop down doesn't reflect the selection (i.e. you click an item but it isn't selected) and you can reproduce this issue in a simple add-in project, please send me that project for testing.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Apr, 2019 08:00:28 Top
Leon Lai Kan




Posts: 200
Joined: 2018-12-20
Andrei,

I finally figured out how to sort out my problem.

I was doing things the wrong way.

What I did (incorrectly):

In the designer, I clicked a Tab
Then I added a Drop Down
I right-clicked on the Drop Down and Chose Add Button

At run time, when we select a button, it does not display in the Drop Down box

What I should have done:

In the designer, click a Tab
Then add a Drop Down
Then go to Properties
Then select Items and add items in the Collector Editor

This time, it works.
When I click any Item, it is displayed in the Drop Down box

I must now learn how to catch the event.

I hope I am now doing things the correct way.

Best Regards,
Leon
Posted 30 Apr, 2019 01:29:57 Top
Andrei Smolin


Add-in Express team


Posts: 17115
Joined: 2006-05-11
Hello Leon,

I can't say that I understand what you do, what you expect to achieve and what you achieve instead.

Here's a bit of useful info.

Using SelectedItemId vs SelectedItemIndex in some Add-in Express Ribbon components
Some of the Ribbon components can be populated with items: combo box, drop down, and gallery. These components provide the SelectedItemId and SelectedItemIndex properties. Internally, these properties are mapped to the getSelectedItemID and getSelectedItemIndex attributes of corresponding elements in the Ribbon XML; see e.g. this page on docs.microsoft.com. These attributes are mutually exclusive. You instruct Add-in Express what of these attributes to use by specifying the SelectedItemIndex property at the design time:
If SelectedItemIndex is -1 (default) at the design time, Add-in Express uses IDs; accordingly, if you need to get the selected item, you use SelectedItemId in your code.
If SelectedItemIndex is set to another value at the design time, Add-in Express uses indices; accordingly, if you need to get the selected item, you use SelectedItemIndex in your code.


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Apr, 2019 02:53:35 Top