Category:DComboBox

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (panel is not passed)
(Undo revision 31469 by TheVingard (talk) Test your changes before you put them on wiki!)
 
Line 7: Line 7:
 
{{Example
 
{{Example
 
|Description=Creates a Combo Box.
 
|Description=Creates a Combo Box.
|Code=local DComboBox = vgui.Create( "DComboBox" )
+
|Code=
DComboBox:SetPos( 5, 5 )
+
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:SetSize( 100, 20 )
 
DComboBox:SetValue( "options" )
 
DComboBox:SetValue( "options" )
Line 14: Line 20:
 
DComboBox:AddChoice( "option B" )
 
DComboBox:AddChoice( "option B" )
 
DComboBox:AddChoice( "option C" )
 
DComboBox:AddChoice( "option C" )
DComboBox.OnSelect = function( index, value )
+
DComboBox.OnSelect = function( self, index, value )
print( value .." was selected!" )
+
print( value .." was selected at index " .. index )
 
end
 
end
 
|Output=<br/>
 
|Output=<br/>
Line 30: Line 36:
 
comboBox:SetValue("All Players")
 
comboBox:SetValue("All Players")
  
comboBox.OnSelect = function(_, value)
+
comboBox.OnSelect = function( _, _, value)
 
print(value.." was selected!")
 
print(value.." was selected!")
 
end
 
end

Latest revision as of 23:23, 9 January 2019

Contents

DescriptionPanelPage

A field with multiple selectable values.

Inherited Functions

Inherits the following functions from DButton and its parents up to 3 levels deep:


Examples

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:


PictureA.png DComboBox2.png DComboBox3.png

option B was selected!

Examples

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

Output:


DComboBoxAllPlayers.png

Bot01 was selected!
Personal tools
Navigation