DListView-Getting selected line as a number?

I have a script which has this line:

local line = self.userselect:GetSelectedLine()

It returns something like ‘1’.
But, I want to retrieve more than one selected line (as a table), so I tried

local line = self.userselect:GetSelected()
for k, v in pairs (line) do
print(k, v)

This prints something like

Panel: [name:DListView_Line][class:Panel][1,0,1678,17]
Panel: [name:DListView_Line][class:Panel][1,17,1678,17]

Instead of a nice number like GetSelectedLine does. How would I get a number table instead of the panel name?

Just to be clear, you’re retrieving the actual DListView_Line panels when you use DListView:GetSelected().

This means you can just call DListView_Line:GetID() in your loop to get their index:

local lines = self.userselect:GetSelected()

for _, line in pairs( lines ) do
    print( line:GetID() )

The ID gets set here: https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dlistview.lua#L350

Alternatively, you could just use the same method the DListView uses to actually get the selected lines, except you could use the index instead of the actual panel.
Then you could just write your own function to get the IDs:

function PANEL:GetSelectedIDs()

    local ret = {}

    for k, v in pairs( self.Lines ) do
        if ( v:IsLineSelected() ) then
            ret[ #ret + 1 ] = k -- return the index instead of the panel itself

    return ret


Thanks a lot! I knew it’d be something obvious I missed.