Well ... I'll show you my code. Maybe could re-use it. If you have any questions please ask.
It's a modified version of the blizzard dropdown code to handle more than one dropdown frame with the same OnLoad/OnClick function.
Let's say there's a table to load into the Dropdown and a variable to save the selected value:
Code:
local dUF.DebuffTypesNumbers = {
[1] = "none",
[2] = "Curse",
[3] = "Disease",
[4] = "Magic",
[5] = "Poison",
[6] = "HealDebuff",
[7] = "Special",
[8] = "Unknown",
}
local SavedValue = 1 -- this value is saved via savedvariables
My code to set up the dropdown is:
Code:
tframe = <a reference to a dropdown frame>
tSource = dUF.DebuffTypesNumbers
tvalue = <the numeric index of DebuffTypesNumbers entry to show>
dUF:OptionsOutputDropDown_OnLoad(tframe, tSource, tvalue)
And the dropdown handling code is:
Code:
---------------------------------------------------------------------------------------------------------------------------------------------------------------
--
----------------------------------------------------------------------------------------------------------------------------------------------------------------
function dUF:OptionsOutputDropDown_OnLoad(frame, source, value)
local tname = frame:GetName()
UIDropDownMenu_Initialize(frame, function()
local entry = { func = function() dUF:OptionsOutputDropDown_OnClick(tname) end }
for i = 1, table.getn(source), 1 do
entry.text = source[i]
entry.value = value;
if (UIDropDownMenu_GetSelectedValue(this) == entry.value) then
entry.checked = true
else
entry.checked = nil
end
UIDropDownMenu_AddButton(entry)
end
end);
UIDropDownMenu_SetSelectedValue(frame, source[value], 1);
UIDropDownMenu_SetSelectedID(frame, value);
if dUF.tocVersion >= 30000 then
UIDropDownMenu_SetText(frame, source[value])
else
UIDropDownMenu_SetText(source[value], frame)
end
end
---------------------------------------------------------------------------------------------------------------------------------------------------------------
--
----------------------------------------------------------------------------------------------------------------------------------------------------------------
function dUF:OptionsOutputDropDown_OnClick(tname)
UIDropDownMenu_SetSelectedID(getglobal(tname), this:GetID())
SavedValue = UIDropDownMenu_GetSelectedID(getglobal(tname))
end