cLib.DListView

VGUI - Containers Updated: Dec 10, 2025

cLib.DListView

Styled list view with columns, sorting, and selection.

Basic Usage

local list = vgui.Create("cLib.DListView", parent)
list:Dock(FILL)

-- Add columns
list:AddColumn("Name"):SetWidth(cLib.Scale(150))
list:AddColumn("Score"):SetWidth(cLib.Scale(80))
list:AddColumn("Status")

-- Add rows
list:AddLine("Player1", 100, "Online")
list:AddLine("Player2", 85, "Away")
list:AddLine("Player3", 150, "Online")

Methods

MethodDescription
AddColumn(name)Add column
AddLine(...)Add row with values
RemoveLine(id)Remove row
Clear()Remove all rows
GetLine(id)Get row by ID
GetLines()Get all rows
GetSelected()Get selected rows
SelectItem(panel)Select row
ClearSelection()Clear selection
SetMultiSelect(bool)Allow multi-select
SortByColumn(col, desc)Sort by column

Callbacks

list.OnRowSelected = function(self, index, row)
    local name = row:GetValue(1)
    local score = row:GetValue(2)
    print("Selected:", name, score)
end

list.OnRowRightClick = function(self, index, row)
    -- Show context menu
end

list.DoDoubleClick = function(self, index, row)
    -- Open details
end

Player List Example

function CreatePlayerList(parent)
    local list = vgui.Create("cLib.DListView", parent)
    list:Dock(FILL)
    list:SetMultiSelect(false)
    
    list:AddColumn("Name"):SetWidth(cLib.Scale(150))
    list:AddColumn("Job"):SetWidth(cLib.Scale(100))
    list:AddColumn("Money"):SetWidth(cLib.Scale(80))
    list:AddColumn("Ping"):SetWidth(cLib.Scale(50))
    
    local function Refresh()
        list:Clear()
        for _, ply in ipairs(player.GetAll()) do
            local line = list:AddLine(
                ply:Nick(),
                ply:getDarkRPVar("job") or "Unknown",
                "$" .. (ply:getDarkRPVar("money") or 0),
                ply:Ping() .. "ms"
            )
            line.player = ply
        end
    end
    
    Refresh()
    
    -- Refresh every 5 seconds
    timer.Create("PlayerListRefresh", 5, 0, function()
        if IsValid(list) then
            Refresh()
        else
            timer.Remove("PlayerListRefresh")
        end
    end)
    
    list.OnRowSelected = function(self, index, row)
        if IsValid(row.player) then
            OpenPlayerProfile(row.player)
        end
    end
    
    list.OnRowRightClick = function(self, index, row)
        if IsValid(row.player) then
            cLib.ShowContextMenu({
                {text = "View Profile", callback = function() 
                    OpenPlayerProfile(row.player) 
                end},
                {text = "Send Message", callback = function() 
                    OpenMessageDialog(row.player) 
                end},
                {divider = true},
                {text = "Report", callback = function() 
                    OpenReportDialog(row.player) 
                end}
            })
        end
    end
    
    return list
end

Sorting

-- Sort by second column, descending
list:SortByColumn(2, true)

-- Click column header to sort
-- Clicking again reverses order