guiGridListGetSelectedItem | Multi Theft Auto: Wiki Skip to content

guiGridListGetSelectedItem

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function returns the row and column indexes of the selected item in a grid list. First selected row and column is (0, 0).

OOP Syntax Help! I don't understand this!

Syntax

int,​ int guiGridListGetSelectedItem ( element gridList )
Required Arguments
  • gridList: the grid list you want to know the selected row index of

Returns

  • int: value1
  • int: value2

Returns the row and column indexes of the selected item if the specified grid list is valid and has a selected item, (-1, -1) if no item is selected, false otherwise.

Code Examples

shared

This code creates a grid list and fills it with the names of the connected players. When the user selects an item, its text (the player name) will be output in the chat box.

addEventHandler('onClientResourceStart', resourceRoot, function()
local playerList = guiCreateGridList(0.8, 0.1, 0.15, 0.6, true)
-- Create a players column in the list
local column = guiGridListAddColumn(playerList, 'Player', 0.85)
-- If the column has been created, fill it with players
if not column then return end
for id, playeritem in ipairs(getElementsByType('player')) do
local row = guiGridListAddRow ( playerList )
guiGridListSetItemText(playerList, row, column, getPlayerName(playeritem), false, false)
end
addEventHandler('onClientGUIClick', playerList, function()
local row, column = guiGridListGetSelectedItem(playerList)
outputChatBox(guiGridListGetItemText(playerList, row, column))
end)
end

See Also

GUI Functions