Thread Tools Display Modes
05/07/15, 04:57 PM   #1
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
How to update a ComboBox database list?

I have a ComboBox dropdown menu that is populated by a database of character names.

I have a function that removed the selected character name from the database and re-selects the currently logged in character.

The problem is, I want to remove that name from the drop down list when this function files.

I have tried GetItems() UpdateItems() and others to no avail.

Does anyone know how to update the list?

I used this to populate it:

Code:
	for k, v in pairs(nameList) do
		local entry = charnameDropdown.dropdown:CreateItemEntry(v, OnItemSelect)
		charnameDropdown.dropdown:AddItem(entry)
	end
I can't seem to find a RemoveItem() function...

It seems if I can re-initialize the main control I can just rebuild it. I'm not sure how to "delete" a control though.

Can I just set it to nil and re-run my initialization function? Testing...

EDIT: Yeah... no. That didn't work. "Duplicate name" still exists.

Last edited by Phinix : 05/07/15 at 05:04 PM.
  Reply With Quote
05/07/15, 05:08 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,011
I think you just need to NIL the entry that you want to delete.
Or clear the list and rebuild it without the entry.
I couldn't find any remove function neither.
  Reply With Quote
05/07/15, 05:14 PM   #3
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
Here is the initialization function:

Code:
local function SetupCharacterDropbox()
	currentChar = GetUnitName("player")
	table.insert(nameList, 1, currentChar)
	for i = 1, 486, 1 do
		if next(MRL.AccountSavedVariables[i].names) ~= nil then
			for n = 1, #MRL.AccountSavedVariables[i].names, 1 do
				local name = MRL.AccountSavedVariables[i].names[n]
				if not Contains(nameList, name) then
					table.insert(nameList, #nameList + 1, name)
				end
			end
		end
	end
	charnameDropdown = WINDOW_MANAGER:CreateControlFromVirtual("CharacterDropdownList", MainFrameListFrameBatchTracking, "ZO_StatsDropdownRow")
    charnameDropdown:SetWidth(300)
    charnameDropdown:SetAnchor(TOPLEFT, MainFrameListFrameBatchTracking, TOPLEFT, -4, 2)
    charnameDropdown:GetNamedChild("Dropdown"):SetWidth(295)
    charnameDropdown.dropdown:SetSelectedItem(currentChar)
    local function OnItemSelect(_, charName, choice)
        currentChar = charName
    end
    for k, v in pairs(nameList) do
        local entry = charnameDropdown.dropdown:CreateItemEntry(v, OnItemSelect)
        charnameDropdown.dropdown:AddItem(entry)
    end
end
Setting charnameDropdown to nil still results in "duplicate name" if I re-run the function. Just rebuilding the list the last part results in duplicate items in the list.
  Reply With Quote
05/07/15, 05:21 PM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,011
You need to use the clear function on the combobox so it gets cleared. If you set it to nil it maybe remmeber the combobox entries somehow?

btw why do you need to loop 486 entries o0
  Reply With Quote
05/07/15, 05:35 PM   #5
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
Originally Posted by Baertram View Post
You need to use the clear function on the combobox so it gets cleared. If you set it to nil it maybe remmeber the combobox entries somehow?

btw why do you need to loop 486 entries o0
Tried charnameDropdown.dropdown:ClearItems() followed by setting it to nil...

Still get: control 'CharacterDropdownList'. Duplicate name.

I am looping through 486 entries because there are 486 recipes in the game. I have a global tracking system that adds character names to a table for each when they learn a recipe (also check for updates at login).

It is actually faster than having a table of 486 entries created for each character.
  Reply With Quote
05/07/15, 05:52 PM   #6
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
Figured it out...

Code:
	
	currentChar = GetUnitName("player")
	charnameDropdown.dropdown:ClearItems()
	for k, v in pairs(nameList) do
		local entry = charnameDropdown.dropdown:CreateItemEntry(v, OnItemSelect)
		charnameDropdown.dropdown:AddItem(entry)
	end
	charnameDropdown.dropdown:SetSelectedItem(currentChar)
Moved OnItemSelect out of the initialization loop so I could call it elsewhere.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » How to update a ComboBox database list?


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