Combobox Selected Item

558
5
Jump to solution
10-26-2012 01:12 PM
JoshObrecht
Occasional Contributor
I have a button add-in that I would like to read the selected value from a combobox add-in. I can't seem to be able to obtain it. I'm assuming it can be done someway, but how?
0 Kudos
1 Solution

Accepted Solutions
AlexanderGray
Occasional Contributor III
You can create a shared variable on the class that gets set whenever the value changed event is triggered.  I am not keen on this sort of thing because it forces you manage an extra variable.  You can also get a reference to the other tool control item from the toolbar and cast it to a variable defined as your custom class that has the combobox and get the value from an instance method.  ToolControl items are usually singletons anyway (only once instance allowed.)  If you need to do it between difference assemblies, you will need to define your own custom interface to call and reference the assembly since you can't cast to a class in the other assembly.

View solution in original post

0 Kudos
5 Replies
LeoDonahue
Occasional Contributor III
Good question.

Is your button add-in and your combo-box add-in functionally different?  In other words, can the button and combo-box exist in the same add-in in a toolbar?  If yes, then you could create a static method in your ComboBox class that just reads and returns the selected value.  YourComboBoxClass.getMeTheSelectedValue()  Or however you want to handle it.

Add-in buttons are in a different package (sorry about the Java reference) than regular framework buttons.  I'm not sure you can search for them like a command item and then get their properties, I could be wrong.

I wish I knew more about what happens during the init() method of Add-ins and how ArcMap processes those. Hypothetically, what would stop you from turning your add-in class that extends ComboBox into a Singleton?  Would you still be able to get an instance of your ComboBox add-in that way, from another Button add-in?

This might help:  Add-in coding patterns
0 Kudos
JoshObrecht
Occasional Contributor
I am using the button and the combobox within the same toolbar and am able to call functions between. However, the only way that I can obtain the value is by Me.Value which cannot be used in a shared function. I know I'm missing something.
0 Kudos
AlexanderGray
Occasional Contributor III
You can create a shared variable on the class that gets set whenever the value changed event is triggered.  I am not keen on this sort of thing because it forces you manage an extra variable.  You can also get a reference to the other tool control item from the toolbar and cast it to a variable defined as your custom class that has the combobox and get the value from an instance method.  ToolControl items are usually singletons anyway (only once instance allowed.)  If you need to do it between difference assemblies, you will need to define your own custom interface to call and reference the assembly since you can't cast to a class in the other assembly.
0 Kudos
LeoDonahue
Occasional Contributor III
What about grouping your button and combobox into an application extension?

In the initialization method of the extension, you could get instances of both types of add-ins for use later.
0 Kudos
AlexanderGray
Occasional Contributor III
If your button is a straight Command, you could have multiple instances of it.  So maintaining a reference to the command on an extension would not work.  The extension will always be a unique instance (by definition), so you can keep a reference to the extension on your two controls and use it to pass values back and forth (this is a model I use a lot.)  You can also place a button on your toolcontrol along side of your combobox, that works nicely some times.
0 Kudos