GuiGridListGetSelectedItem

From Multi Theft Auto: Wiki
Revision as of 19:05, 19 June 2024 by Tracer (talk | contribs) (Changed syntax)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

Syntax

int, int guiGridListGetSelectedItem ( element gridList )

OOP Syntax Help! I don't understand this!

Method: GuiGridList:getSelectedItem(...)


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.

Example

Click to collapse [-]
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.

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

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