GuiGridListClear: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(OOP syntax)
 
(One intermediate revision by the same user not shown)
Line 16: Line 16:


==Example==  
==Example==  
This example creates a grid list, puts 2 items in to display the text "Hello" and "world" and clears the grid list after 5 seconds.
This creates a player list and then clears it when a button is clicked:
<syntaxhighlight lang="lua">function clientsideResourceStart ()
<syntaxhighlight lang="lua">
        -- Create the grid list element
-- create the grid list
local testList = guiCreateGridList ( 0.45, 0.45, 0.15, 0.15, true )  
local playerList = guiCreateGridList(0.80, 0.40, 0.15, 0.35, true)
        -- Create a column in the list and add 2 rows displaying "Hello" text and "world" text
guiGridListAddColumn(playerList, "#", 0.15)
local column = guiGridListAddColumn( testList, "test", 0.85 )  
guiGridListAddColumn(playerList, "Player", 0.75)
guiGridListSetItemText ( testList, guiGridListAddRow ( testList ), column, "Hello", false, false )
 
guiGridListSetItemText ( testList, guiGridListAddRow ( testList ), column, "World", false, false )
-- fill the grid list with player names
        -- Set a timer to call the guiGridListClear function to clear the grid list items in 5 seconds
for index, player in ipairs(getElementsByType("player")) do
setTimer ( guiGridListClear, 5000, 1, testList )  
    guiGridListAddRow(playerList, index, getPlayerName(player))
end
end
addEventHandler ( "onClientResourceStart", resourceRoot, clientsideResourceStart )</syntaxhighlight>
 
-- create a button to clear the grid list
local clearButton = guiCreateButton(0.80, 0.30, 0.15, 0.05, "Clear list", true)
 
-- when the button is clicked, clear the grid list
addEventHandler("onClientGUIClick", clearButton, function()
    guiGridListClear(playerList)
end)
</syntaxhighlight>


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

Latest revision as of 17:47, 22 December 2022

This function clears all the data from a grid list.

Syntax

bool guiGridListClear ( element gridList )

OOP Syntax Help! I don't understand this!

Method: GuiGridList:clear(...)


Required Arguments

  • gridList: The grid list element to be cleared

Returns

Returns true if the grid list element is valid and has been cleared successfully, false otherwise.

Example

This creates a player list and then clears it when a button is clicked:

-- create the grid list
local playerList = guiCreateGridList(0.80, 0.40, 0.15, 0.35, true)
guiGridListAddColumn(playerList, "#", 0.15)
guiGridListAddColumn(playerList, "Player", 0.75)

-- fill the grid list with player names
for index, player in ipairs(getElementsByType("player")) do
    guiGridListAddRow(playerList, index, getPlayerName(player))
end

-- create a button to clear the grid list
local clearButton = guiCreateButton(0.80, 0.30, 0.15, 0.05, "Clear list", true)

-- when the button is clicked, clear the grid list
addEventHandler("onClientGUIClick", clearButton, function()
    guiGridListClear(playerList)
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