WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Setting initial value of UIDropDownMenu (https://www.wowinterface.com/forums/showthread.php?t=54140)

Arcilux 08-06-16 01:18 PM

Setting initial value of UIDropDownMenu
 
I have a UIDropDownMenu for users to set an option in my addon. I initialize the drop down menu with the following code:

Code:

function IP_BuildLimitDropdown()
        local info = UIDropDownMenu_CreateInfo();
        info.text = "1";
        info.value = 1;
        info.func = IP_LimitSelect;
        UIDropDownMenu_AddButton(info);
        info = UIDropDownMenu_CreateInfo();
        info.text = "2";
        info.value = 2;
        info.func = IP_LimitSelect;
        UIDropDownMenu_AddButton(info);
        info = UIDropDownMenu_CreateInfo();
        info.text = "3";
        info.value = 3;
        info.func = IP_LimitSelect;
        UIDropDownMenu_AddButton(info);
end

I store the value the player selects in a saved variable and then when they press the button to open up the options window I have the following code:

Code:

InstanceProfits_RecentHistory:Show();
InstanceProfits_RecentHistory:SetFrameStrata("HIGH");
InstanceProfits_RecentHistory:Raise();
UIDropDownMenu_SetSelectedID(InstanceProfits_RecentHistory_LimitDropDown, recentLimit);

However, when I first open the frame the text in the drop down box says "Custom" which isn't even an option in the list. If I click on the drop down box it shows the correct selected value and immediately updates the text. I get the same result if I change SetSelectedID to SetSelectedValue or SetSelectedName.

Is anybody familiar with this behavior or can tell me where I'm going wrong? The on click handler appears to be working correctly, and it uses similar code:

Code:

function IP_LimitSelect(self, arg1, arg2, checked)
        if not checked then
                UIDropDownMenu_SetSelectedValue(InstanceProfits_RecentHistory_LimitDropDown, self.value);
                recentLimit = self.value;
                IP_ShowRecent();
        end
end

So I'm thinking the problem has to be somewhere around where I initialize the drop down, but I'm not sure where.

Arcilux 08-06-16 07:31 PM

Got it figured out, the Initialize function called from the XML was being called before my addon was fully loaded, so the SavedVariable wasn't set yet. I added
Code:

InstanceProfits_RecentHistory_LimitDropDown.selectedName = recentLimit;
InstanceProfits_RecentHistory_LimitDropDown.selectedValue = recentLimit;
UIDropDownMenu_SetSelectedID(InstanceProfits_RecentHistory_LimitDropDown, recentLimit);

to the event handler that checks for my addon being loaded and it works.


All times are GMT -6. The time now is 07:56 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI