Without knowing it was in another panel, I have also used that technique: rebuilding and replacing the full string of names.
This is faster and easier than searching in the content string and replacing a piece (you need to store what is before and what is after) of it.
I put this in a separate method that I can call for any listbox: RefreshListBoxContent(memoryblock). So, only one program but re-used several times 🙂
It is based on a memory block in my case as I have sound banks as memory blocks and I extract the program names from the bank (20 char string).
Here is the code you can get inspired from:
RefreshBankListBox = function(mbBank)
FileSize = mbBank:getSize()
if FileSize == 116622 then
sListBoxContent = ""
for i=0, 98 do
UnpackedTempData = utils.unpackDsiData(mbBank:getRange (438+i*1178, 24))
sTemp = trim(UnpackedTempData:getRange (0, 20):toString()) -- Remove blanks
sTemp = sTemp:gsub("'", " ") -- Replace ' by a space as it gives issues in the listbox
sTemp = sTemp:gsub("\"", " ") -- Replace " by a space as it gives issues in the listbox
if i==0 then
sListBoxContent = sListBoxContent..string.format("%s", "P1 "..sTemp)
else
sListBoxContent = sListBoxContent..string.format("\n%s", "P"..tostring(i+1).." "..sTemp)
--sListBoxContent = sListBoxContent..", \""..sTemp.."\""
end
end
return sListBoxContent
else
utils.warnWindow("Refresh bank list box", "Error: bank data not of correct size. Should be 116622 and is "..FileSize.." bytes.")
end
end
To use it:
lbUser1:setPropertyString ("uiListBoxContent", RefreshBankListBox(mbUser1))
With lbUser1 being a uiListBox declared as:
lbUser1 = panel:getListBox("User1")