Fanning Software Consulting

Current Value of a Droplist Widget

QUESTION: How can I obtain the current value of a droplist widget in my program?

ANSWER: It is an odd thing with droplist widgets, because even though you can set a droplist widget's value with the Value keyword, if you try to obtain the value of a droplist with code like this:

   Widget_Control, droplistID, Get_Value=currentValue

you get the error message that "Class of specified widget has no value."

So how can you get it!?

Well, you can't get it directly, that's for sure. Here is what I usually do.

I normally save the "value" of the droplist in the user value when I create the droplist. This stores it in a location where I can find it easily.

   dropListValues = ['Dog', 'Cat', 'Pig', 'Coyote']
   dropListID = Widget_Droplist(baseID, Value=dropListValues, UValue=dropListValues)

I store the droplist identifier in the "info" structure where I keep all of the information that I need to run my widget program. I can access this info structure from within any event handler module.

Thus, to get the current value of the droplist, I use Widget_Info, which gives me the current droplist index number, and the other information I have stored like this:

   currentIndex = Widget_Info(info.dropListID, /DropList_Select)
   Widget_Control, info.dropListID, Get_UValue=droplistValues
   Print, 'Current Droplist Selection: ', droplistValues[currentIndex]

See the Dynamic_Menus_Droplist_Events event handler in the program Dynamic_Menus for working program illustration.

Google
 
Web Coyote's Guide to IDL Programming