Garry's Mod Wiki

DComboBox

Description

A field with multiple selectable values.

Parent

Derives from DButton.

Methods

number DComboBox:AddChoice( string value, any data = nil, boolean select = false, string icon = "nil" )
Adds a choice to the combo box.
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.
DComboBox:Clear()
Clears the combo box's text value, choices, and data values.
DComboBox:CloseMenu()
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.
DComboBox:OpenMenu()
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.

Example

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!

Example

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

Page Links


Special Pages


Wikis

?

Render Time: 61ms

DB GetPage 27
Generate Html 5
SaveChanges (1) 9
Render Body 0
Render Sidebar 17