GUI - What's wrong with my code ?


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 :

        //actionsPanel is declared as file local.
        actionsPanel = vgui.Create('DListBox', mainFrame)
	actionsPanel:SetSize(208, 258)
	actionsPanel:SetPos(408, 29)
	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 .. "\"")
		--RRP End
		actionsPanel.DPanelList:AddItem( actionsPanel, item )
		return item

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
local List = vgui.Create(“DListView”, Frame)

for k,v in pairs(player.GetAll()) do
List:AddLine(v:Name(), v:UserID())

function List:OnRowSelected( id, line )
print("Name: "…line:GetColumnText(1), "USerID: "…line:GetColumnText(2))

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 Header, so you can do:


Ok problem solved thanks thefreeman193 and _FR_Starfox64.