DListView OnClickLine Issue [Short Code]

So I am made a DListView as such:



local list1 = vgui.Create("DListView", shoplist3)
	list1:Dock( FILL )
	list1:SetMultiSelect(false)
	list1:AddColumn("Items")
	list1:AddColumn("Number")
	list1:AddLine( "Item1", "10" )
	list1:AddLine( "Item2", "20" )
	list1:AddLine( "Item3", "30" )


What I’d like is for when a player selects a line from the list the first value associated with the selected line gets printed as a string.

Example 1) Player selects the line that says “Item1” “10”
Console prints: “Item1”

Example 2) Player selects the line that says “Item3” “30”
Console prints: “Item3”

My attempt is an embarrassment to the lua society and does not seem to work:



list1.OnClickLine = function( parent, line, isselected )
	print( list1:GetLine( list1:GetSelected( line ):GetValue(1) )
end


Where did you put your OnClickLine? It should be after SetMultiSelect. Or you could look at

DListView/DoDoubleClick

It looks like this



function SomeFunction()
//Omitting lots of code
...
        local list1 = vgui.Create("DListView", shoplist3)
	        list1:Dock( FILL )
	        list1:SetMultiSelect(false)
	        list1:AddColumn("Items")
	        list1:AddColumn("Number")
	        list1:AddLine( "Item1", "10" )
	        list1:AddLine( "Item2", "20" )
	        list1:AddLine( "Item3", "30" )

        list1.OnClickLine = function( parent, line, isselected )
	        print( list1:GetLine( list1:GetSelected( line ):GetValue(1) )
        end
//omitting rest of code
...
end


This gets the first value of the list1 just how I want it to:



list1.OnClickLine = function( parent, line, isselected )
	print( list1:GetLine( 1 ):GetValue(1) ) // What is messed up is what's inside list1:GetLine()
end


It’s just actually getting it to where whatever line I click on provides the first entry on the line. That link your provided does help a lot though.

Try this:



print(line:GetValue(1))


Because the command returns DListViewLine, not number.

From wiki:



DListView:OnClickLine( DListViewLine line, boolean isSelected )


The line argument passed to the OnClickLine function is just the actual line object, so you can create a table, iterate through the line columns (using ipairs to preserve the order) and add the value of the column to the table. Then, you can use the unpack function to present the table as a vararg to the print function. This will print the contents with a space in between.



dlv.OnClickLine = function(self, line, bClear)
	local textcolumns = {}
	for i, v in ipairs(line.Columns) do
		textcolumns* = v.Value
	end
	print(unpack(textcolumns))
end


If you want to use this without printing varargs, you can use string.Explode.

Thanks! It works perfectly now.