GuiGridListClear: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
 
(5 intermediate revisions by 5 users not shown)
Line 6: Line 6:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool guiGridListClear ( element gridList )
bool guiGridListClear ( element gridList )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[Element/GUI/Gridlist|GuiGridList]]:clear}}


===Required Arguments===  
===Required Arguments===  
Line 15: 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">
local testList = guiCreateGridList ( 0.45, 0.45, 0.15, 0.15, true ) -- Create the grid list element
-- create the grid list
local column = guiGridListAddColumn( testList, "test", 0.85 ) -- Create a column in the list and add 2 rows displaying "Hello" text and "world" text
local playerList = guiCreateGridList(0.80, 0.40, 0.15, 0.35, true)
guiGridListSetItemText ( testList, guiGridListAddRow ( testList ), column, "Hello", false, false )
guiGridListAddColumn(playerList, "#", 0.15)
guiGridListSetItemText ( testList, guiGridListAddRow ( testList ), column, "World", false, false )
guiGridListAddColumn(playerList, "Player", 0.75)
setTimer ( guiGridListClear, 5000, 1, testList ) -- Set a timer to call the guiGridListClear function to clear the grid list items in 5 seconds
 
-- fill the grid list with player names
for index, player in ipairs(getElementsByType("player")) do
    guiGridListAddRow(playerList, index, getPlayerName(player))
end
end
addEventHandler ( "onClientResourceStart", getRootElement(), 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}}

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