Fanning Software Consulting

Identifying Base Widgets from Tab Widget Events

QUESTION: In my application, base widgets (with all their accompanying widgets) are added to a tab widget in an arbitrary order based on user input in the program. This is a problem for me, because when the user clicks on a tab, I need to know which base widget that tab is associated with. But all I receive in my event handler is the index number of the base widget causing the tab event. What I really need is the ID of the base widget that is associated (at the moment) with that index number. I can't find a way, using Widget_Control or Widget_Info to obtain this ID. Can you suggest a way to do it?

ANSWER: I think the only possible solution is to traverse the widget heirarchy, starting with the tab widget, which is identified as EVENT.ID in your event handler. The children of this widget are the base widgets you have added to the tab widget, in the order in which you added them. Thus, you can use the tab index number, returned in your event handler as EVENT.TAB, to fish out base widget ID associated with that index number. The code will look like this.

   CASE event.tab OF
       0: theBase = Widget_Info(event.id, /Child)
       ELSE: BEGIN
          theChild = Widget_Info(event.id, /Child)
          FOR j=1,event.tab DO BEGIN
             theChild = Widget_Info(theChild, /Sibling)
          ENDFOR
          theBase = theChild
          END
    ENDCASE

Google
 
Web Coyote's Guide to IDL Programming