Hello,
I appologies for having to post this type of topic, but I seriously don't know how to make this code working.
For the context, you have DFrame in which you want to add DListBox which lists all cop-folders of a player. Server side there's no problems. The error is happening client side, when adding elements to the DListBox. I have overwritten the function AddItem of DListBox, so I could add custom code when user selects an element in this list.
Here is the code :
[code]
//actionsPanel is declared as file local.
actionsPanel = vgui.Create('DListBox', mainFrame)
actionsPanel:SetSize(208, 258)
actionsPanel:SetPos(408, 29)
actionsPanel:SetMultiple(false)
actionsPanel.AddItem = function(strLabel)
//Error here.
local item = vgui.Create( "DListBoxItem", actionsPanel )
item:SetMother( actionsPanel )
item:SetText( strLabel )
--RRP Start
item.DoClick = function()
if (foundUser != nil) then
LocalPlayer():ConCommand("rp_getfolderaction \"" .. foundUser .. "\" \"" .. strLabel .. "\"")
end
end
--RRP End
actionsPanel.DPanelList:AddItem( actionsPanel, item )
return item
end
[/code]
I get an error telling me strLabel is not a string but a panel. The most strange in this is that it's not a panel, it's an integer converted to string.
The wiki says that DListBox is shit, you should use DListView and you won't need to override anything in the VGUI, there is a hook (OnRowSelected) that is called whenever a line is selected.
Have a look at some of my code that simplified a bit
[LUA]
local List = vgui.Create("DListView", Frame)
List:SetMultiSelect(false)
List:AddColumn("Name")
List:AddColumn("UserID")
for k,v in pairs(player.GetAll()) do
List:AddLine(v:Name(), v:UserID())
end
function List:OnRowSelected( id, line )
print("Name: "..line:GetColumnText(1), "USerID: "..line:GetColumnText(2))
end
[/LUA]
Thank you, however, I can't use DListView, because i don't want a table I want a simple list of integers like Visual Basic ListBox.
I don't need any table of all sort...
You could still use DListView and only use one column.
But i'll then have the display of this one column's title, isn't it ?
If that's true, then like I said having a column text is NOT wanted !
The header for a DListView_Column is added as a member [i]Header[/i], so you can do:
[code]
List:AddColumn("Name").Header:Hide()
List:AddColumn("UserID").Header:Hide()
[/code]
Ok problem solved thanks thefreeman193 and _FR_Starfox64.
Sorry, you need to Log In to post a reply to this thread.