Garry's Mod Wiki

DPanelList:SetAutoSize

  DPanelList:SetAutoSize( boolean shouldSizeToContents )

Description

Sets the DPanelList to size its height to its contents. This is set to false by default.

Arguments

1 boolean shouldSizeToContents
Whether to size to the height of the DPanelList contents.

Example

Creates a list with buttons, auto sizes the list to the buttons

local panelList = vgui.Create("DPanelList", self) panelList:SetAutoSize(true) for i = 1, 5 do local button = vgui.Create("DButton", self) button:SetText("Button " .. i) panelList:AddItem(button) end -- Ensure PerformLayout is called (which sets the list height to the content height) panelList:InvalidateLayout()
Output:
list-of-buttons.png