guiGridListGetSelectedItems | Multi Theft Auto: Wiki Skip to content

guiGridListGetSelectedItems

Client-side
Server-side
Shared

This function returns the items selected in the specified grid list.

OOP Syntax Help! I don't understand this!

  • Method:gui-gridlist:getSelectedItems(...)
  • Variable: .selectedItems

Syntax

table|false guiGridListGetSelectedItems ( ​gui-gridlist gridList )
Required arguments
  • gridList: The grid list which selected items you want to retrieve.

Returns

Returns a table over the selected items in the grid list if everything was successful or false if invalid arguments were passed.

Table format:

table = {
[1] = {
["column"], -- has the first selected item's column ID
["row"] -- has the first selected item's row ID
},
[2] = {
["column"],-- has the second selected item's column ID
["row"] -- has the second selected item's row ID
},
...
}
  • table|false: selected items

Code Examples

client
-- This example creates a grid list of all players, clicking "Selected" button will then use guiGridListGetSelectedItems to show all selected items.
local playerWindow = guiCreateWindow(526, 230, 291, 284, "", false)
local gridlistPlayers = guiCreateGridList(9, 23, 272, 201, false, playerWindow)
guiGridListAddColumn(gridlistPlayers, "Players", 0.9)
guiGridListSetSelectionMode(gridlistPlayers, 1) -- So can select many players
for _, players in ipairs(getElementsByType("player")) do
local row = guiGridListAddRow(gridlistPlayers)
guiGridListSetItemText(gridlistPlayers, row, 1, getPlayerName(players), false, false)
end
local buttonSelectedPlayer = guiCreateButton(9, 227, 272, 20, "Selected", false, playerWindow)
function seeSelected()
local selected = guiGridListGetSelectedItems(gridlistPlayers)
for i, data in ipairs(selected) do -- Loops through all selected items
outputChatBox(guiGridListGetItemText(gridlistPlayers, data["row"], 1)) -- Shows player name of selected players
end
end
addEventHandler("onClientGUIClick", buttonSelectedPlayer, seeSelected, false)

See Also

GUI Functions