GuiComboBoxGetSelected: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Needs Example}}
{{Client function}}
{{Client function}}
__NOTOC__
__NOTOC__
Line 7: Line 6:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int guiComboBoxGetSelected ( element comboBox )
int guiComboBoxGetSelected ( element comboBox )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[Element/GUI/Combobox|GuiComboBox]]:getSelected|selected|guiComboBoxSetSelected}}


===Required Arguments===  
===Required Arguments===  
Line 13: Line 13:


===Returns===
===Returns===
Returns the index of the selected item if the specified combobox is valid and has a selected item, ''-1'' if no item is selected, ''false'' or ''nil'' otherwise.
Returns the index of the selected item if the specified combobox is valid and has a selected item, ''-1'' if no item is selected, ''nil'' otherwise.


==Example==
==Example==
This example outputs selected item's text and ID to the chat.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--Todo..
addCommandHandler("getSelected",
function (command)
 
local item = guiComboBoxGetSelected(comboBox)
local text = guiComboBoxGetItemText(comboBox, item)
 
outputChatBox("Currently selected item with ID: " .. tostring(item) .. " and with text: " .. text)
 
end)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{GUI functions}}
{{GUI functions}}
{{GUI_events}}

Latest revision as of 23:38, 2 January 2019

This function returns the index of the selected combobox item.

Syntax

int guiComboBoxGetSelected ( element comboBox )

OOP Syntax Help! I don't understand this!

Method: GuiComboBox:getSelected(...)
Variable: .selected
Counterpart: guiComboBoxSetSelected


Required Arguments

  • comboBox: the combobox you want to know the selected item index of

Returns

Returns the index of the selected item if the specified combobox is valid and has a selected item, -1 if no item is selected, nil otherwise.

Example

This example outputs selected item's text and ID to the chat.

addCommandHandler("getSelected",
function (command)

local item = guiComboBoxGetSelected(comboBox)
local text = guiComboBoxGetItemText(comboBox, item)

outputChatBox("Currently selected item with ID: " .. tostring(item) .. " and with text: " .. text)

end)

See Also

General functions

Browsers

Buttons

Checkboxes

Comboboxes

Edit Boxes

Gridlists

Memos

Progressbars

Radio Buttons

Scrollbars

Scrollpanes

Static Images

Tab Panels

Tabs

Text Labels

Windows

Input

GUI