Garry's Mod Wiki

DComboBox:OnSelect

  DComboBox:OnSelect( number index, string value, any data )

Description

Called when an option in the combo box is selected. This function does nothing by itself, you're supposed to overwrite it.

Arguments

1 number index
The index of the option for use with other DComboBox functions.
2 string value
The name of the option.
3 any data
The data assigned to the option.

Example

Creates a combo box that controls the color of the background panel.

local frame = vgui.Create("DFrame") frame:SetSize( 500, 500 ) frame:Center() frame:MakePopup() -- Background panel local BGPanel = vgui.Create( "DPanel", frame ) BGPanel:Dock( FILL ) local cbox = vgui.Create( "DComboBox", BGPanel ) cbox:SetPos( 5, 5 ) cbox:SetSize( 190, 20 ) cbox:SetValue( "Pick a color" ) -- Default text -- Color choices cbox:AddChoice( "Red", Color( 255, 0, 0 ) ) cbox:AddChoice( "Orange", Color( 255, 128, 0 ) ) cbox:AddChoice( "Yellow", Color( 255, 255, 0 ) ) cbox:AddChoice( "Green", Color( 0, 255, 0 ) ) cbox:AddChoice( "Blue", Color( 0, 0, 255 ) ) cbox:AddChoice( "Indigo", Color( 64, 0, 255 ) ) cbox:AddChoice( "Violet", Color( 128, 0, 255 ) ) cbox:AddChoice( "Pink", Color( 255, 0, 255 ) ) function cbox:OnSelect( index, text, data ) -- Set background panel color BGPanel:SetBackgroundColor( data ) end