guiGridListGetSelectedItem | Multi Theft Auto: Wiki Skip to content

guiGridListGetSelectedItem

Client-side
Server-side
Shared

Pair: guiGridListSetSelectedItem

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|false, ​int guiGridListGetSelectedItem ( ​gui-gridlist gridList )
Required arguments
  • gridList: The grid list you want to know the selected row index of.

Returns

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.

  • int|false: row
  • int: column

Code Examples

client

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.

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)

See Also

GUI Functions