Thread Tools Display Modes
07-06-10, 07:37 AM   #1
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
Dynamic creation of UIDropDownMenuTemplate

So currently i'm having a major issue with UIDropDownMenuTemplate, in my project i dynamically create dropdown boxes but my issue is that when i try to change the value of the first one created, the value of the last one created changes instead how can i avoid this?

http://pastey.net/138341
  Reply With Quote
07-06-10, 08:24 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Just a quick guess:

Code:
19    local function OnClick(self)   
20         UIDropDownMenu_SetSelectedID(self, self:GetID())   
21         ErrDB.ErrRdr[i] = self:GetText()   
22     end
  Reply With Quote
07-06-10, 08:49 AM   #3
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
yeah that was my first thought aswell :/ but no luck in terms of changing it to dropdownName, this is the "updated" code, which now throws errors about self

Code:
	dropdownName = "optionDropdownRedirect"..NumOptions

	dropdownName = CreateFrame("Frame", "optionDropdownRedirect"..NumOptions, CategoryFrame, "UIDropDownMenuTemplate")
	dropdownName:ClearAllPoints()
	dropdownName:SetPoint("TOPLEFT", 320, distanceTop + 4)

	local function dropdownName_OnClick(self)
   		UIDropDownMenu_SetSelectedID(dropdownName, self:GetID())
		ErrDB.ErrRdr[i] = self:GetText()
	end

	local function initialize(self, level)
		local info = UIDropDownMenu_CreateInfo()

		for k,v in pairs(RedirectOptions) do
			info = UIDropDownMenu_CreateInfo()
			info.text = v
			info.value = v
			info.func = function() dropdownName_OnClick() end
			UIDropDownMenu_AddButton(info, level)
		end
	end

	UIDropDownMenu_Initialize(dropdownName, initialize)
	UIDropDownMenu_SetSelectedName(dropdownName, ErrDB.ErrRdr[i])
i fear it's something really simple but i've only just started programming addons after going a year without programming a single thing, so getting back in shape takes time
  Reply With Quote
07-06-10, 09:36 AM   #4
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Ah ... I remember ... multiple dropdown frames. Lovely thingi

Additionally pass the the parent frame with every new button:

Code:
function initialize(self, level)   
     local info = UIDropDownMenu_CreateInfo()   
     for k,v in pairs(RedirectOptions) do   
         info = UIDropDownMenu_CreateInfo()   
         info.text = v   
         info.value = v   
         info.arg1 = self
         info.func = OnClick   
         UIDropDownMenu_AddButton(info, level)   
     end   
end
info.arg1 is passed to info.func and can be used for UIDropDownMenu_SetSelectedID() to modify the proper dropdown frame.

Code:
function OnClick(self, parentDropdownFrame)   
      UIDropDownMenu_SetSelectedID(parentDropdownFrame, self:GetID())  
end
  Reply With Quote
07-06-10, 09:40 AM   #5
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
You sir, saved my day! thanks a thousand for helping me with this, been bashing my head against the wall since yesterday -.-

Oh! while you'r nearby, any idea why
Code:
UIDropDownMenu_SetSelectedName(dropdownName, ErrDB.ErrRdr[i])
wont seem to work? ErrDB.ErrRdr contains strings with names exactly matching those of my dropdown
  Reply With Quote
07-06-10, 09:54 AM   #6
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Hm.

Code:
UIDropDownMenu_SetSelectedName(dropdownName, "Raidwarning")
does the job.

Must be something with ErrDB.ErrRdr or the index i.
  Reply With Quote
07-06-10, 10:02 AM   #7
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
yeah true, will look into it thanks for the help though!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Dynamic creation of UIDropDownMenuTemplate


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