Garry's Mod Wiki




A field with multiple selectable values.


Derives from DButton.


number DComboBox:AddChoice( string value, any data = nil, boolean select = false, string icon = "nil" )
Adds a choice to the combo box.
Adds a spacer below the currently last item in the drop down. Recommended to use with DComboBox:SetSortItems set to false.
DComboBox:ChooseOption( string value, number index )
Selects a combo box option by its index and changes the text displayed at the top of the combo box.
DComboBox:ChooseOptionID( number index )
Selects an option within a combo box based on its table index.
Clears the combo box's text value, choices, and data values.
Closes the combo box menu. Called when the combo box is clicked while open.
any DComboBox:GetOptionData( number index )
Returns an option's data based on the given index.
string DComboBox:GetOptionText( number index )
Returns an option's text based on the given index.
string DComboBox:GetOptionTextByData( string data )
Returns an option's text based on the given data.
string, any DComboBox:GetSelected()
Returns the currently selected option's text and data
number DComboBox:GetSelectedID()
Returns the index (ID) of the currently selected option.
boolean DComboBox:GetSortItems()
Returns an whether the items in the dropdown will be alphabetically sorted or not. See DComboBox:SetSortItems.
boolean DComboBox:IsMenuOpen()
Returns whether or not the combo box's menu is opened.
DComboBox:OnSelect( number index, string value, any data )
Called when an option in the combo box is selected. This function does nothing by itself, you're supposed to overwrite it.
Opens the combo box drop down menu. Called when the combo box is clicked.
DComboBox:SetSortItems( boolean sort )
Sets whether or not the items should be sorted alphabetically in the dropdown menu of the DComboBox. If set to false, items will appear in the order they were added by DComboBox:AddChoice calls. This is enabled by default.
DComboBox:SetValue( string value )
Sets the text shown in the combo box when the menu is not collapsed.


Creates a Combo Box.

local frame = vgui.Create( "DFrame" ) frame:SetSize( 300, 250 ) frame:Center() frame:MakePopup() local DComboBox = vgui.Create( "DComboBox", frame ) DComboBox:SetPos( 5, 30 ) DComboBox:SetSize( 100, 20 ) DComboBox:SetValue( "options" ) DComboBox:AddChoice( "option A" ) DComboBox:AddChoice( "option B" ) DComboBox:AddChoice( "option C" ) DComboBox.OnSelect = function( self, index, value ) print( value .." was selected at index " .. index ) end
Output: option B was selected at index 2


Create a Combo Box with all players

local comboBox = vgui.Create("DComboBox") comboBox:SetPos(5, 5) comboBox:SetSize(100, 20) comboBox:SetValue("All Players") comboBox.OnSelect = function( _, _, value) print(value.." was selected!") end for k,v in pairs(player.GetAll()) do comboBox:AddChoice(v:Name()) end

Special Pages



Render Time: 53ms

DB GetPage 32
Generate Html 5
SaveChanges (1) 6
Render Body 0
Render Sidebar 7