Thread Tools Display Modes
08-06-16, 01:18 PM   #1
Arcilux
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Oct 2015
Posts: 4
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.
  Reply With Quote
08-06-16, 07:31 PM   #2
Arcilux
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Oct 2015
Posts: 4
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.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Setting initial value of UIDropDownMenu

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off