Thread Tools Display Modes
07-09-06, 12:56 AM   #1
Sastira
A Murloc Raider
Join Date: Jul 2006
Posts: 7
DropDown/Combo Boxes Programatically

Greetings!

I've hit a bit of a snag when it comes to generating comboboxes programatically.

I want to generate the contents of the box based on the contents of an array. I have everything working as far as the array goes, but when I try to generate the contents of the box, nothing shows up.

I took a look inside the xml that wow uid generates, and tried to copy that to a degree, hoping it would work. It did not, obviously.

Here is what wowuides generated:

Code:
local cb_init_fn = function()
  local info
  info = {}
  info.text = "priest"
  info.func = function() UIDropDownMenu_SetSelectedID(IntelliTargetFormTargetPanelddTarget1, this:GetID(), 0); UpdateTargetList("ddTarget1"); end
  UIDropDownMenu_AddButton(info);
end
UIDropDownMenu_Initialize(this, cb_init_fn)
Here is what I tried to do:
Please note:
InitTable is a table populated with strings.
current is the name of the current drop down box being acted upon (I pass it around to do stuff)
DDID is the return of getglobal("IntelliTargetFormTargetPanel"..name) (where name is the name of the dropdown box)
Code:
function MakeButtons(DDID,current)
	DEFAULT_CHAT_FRAME:AddMessage("calling makebuttons");
	local i = 0;
	for  i = 1, table.getn(InitTable) do
	DEFAULT_CHAT_FRAME:AddMessage("inside for: ".. InitTable[i]);
		local info
		info = {}
		info.text = InitTable[i];
		info.func = function() 
			UIDropDownMenu_SetSelectedID(DDID, this:GetID(), 0);
			UpdateTargetList(current);
		end
		UIDropDownMenu_AddButton(info);
	end
end
I get no errors when I run this, but I also get nothing in my dropdown box. Any ideas?

Thanks in advance!!
  Reply With Quote
07-09-06, 05:10 AM   #2
Sastira
A Murloc Raider
Join Date: Jul 2006
Posts: 7
Figured it out. I should sleep more.
  Reply With Quote
07-09-06, 01:54 PM   #3
Hevanus
A Deviate Faerie Dragon
 
Hevanus's Avatar
Join Date: Jun 2006
Posts: 15
Would be nice to see a tutorial on this - I'm having a little trouble figuring out how to work with them myself. Part of the problem is that all the examples I've seen seem to populate the dropdowns at initialization time, whereas I want to be able to populate them dynamically (such as when the frame is made visible, or when something is selected from a different dropdown).

Edit: Also, what were you doing wrong?

Last edited by Hevanus : 07-09-06 at 02:11 PM.
  Reply With Quote
07-11-06, 04:47 AM   #4
Sastira
A Murloc Raider
Join Date: Jul 2006
Posts: 7
Mine actually does exactly that. It populates the dropdown when the "OnShow" event is fired. I call a function then that basically does exactly what the others do on initialization.

The problem I was having is that I was attempting to pass variables to my population function inside the UIDropDownMenu_Initialize(); function. The second argument is the /name/ of the function, WITHOUT any parentheses or passed variables or anything.

UIDropDownMenu_Initialize(DDID, MakeButtons);

That's what it ended up being. Instead of passing the variables I needed, I just added a global (I hate globals, but alas).

Gimmie a bit.. I'll throw together a small wowUI project that populates a dropdown when you hit a button and throw it up here for you.
  Reply With Quote
07-11-06, 05:00 AM   #5
Sastira
A Murloc Raider
Join Date: Jul 2006
Posts: 7
Bleh. The servers are down ATM, so I can't test this project to make sure it works before posting it. I'll post it tomorrow after I test it.
  Reply With Quote
07-11-06, 01:19 PM   #6
Sastira
A Murloc Raider
Join Date: Jul 2006
Posts: 7
Here you go:
Attached Files
File Type: zip DDBExample.zip (2.8 KB, 877 views)
  Reply With Quote
07-12-06, 02:48 AM   #7
Hevanus
A Deviate Faerie Dragon
 
Hevanus's Avatar
Join Date: Jun 2006
Posts: 15
Much appreciated, thanks! I'll take a look.

The other thing I know is going to bite me is the limit on entires in a dropdown. I'll have to either figure out how to do nested dropdown lists or do a double dropdown where it does something along the lines of the first letting the user pick the first letter of what will appear in the second.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » DropDown/Combo Boxes Programatically


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