GuiGridListGetSelectedItems: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Fixed completely useless example)
Line 32: Line 32:
==Example==
==Example==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--Vladislav_Nenakhov
-- This example creates a grid list of all players, clicking "Selected" button will then use guiGridListGetSelectedItems to show all selected items.
--Create window
playerWindow = guiCreateWindow(526, 230, 291, 284, "", false)
playerWindow = guiCreateWindow(526, 230, 291, 284, "", false)
guiWindowSetSizable(playerWindow, false)
gridlistPlayers = guiCreateGridList(9, 23, 272, 201, false, playerWindow)
gridlistPlayers = guiCreateGridList(9, 23, 272, 201, false, playerWindow)
guiGridListAddColumn(gridlistPlayers, "Players", 0.9)
guiGridListAddColumn(gridlistPlayers, "Players", 0.9)
guiGridListSetSelectionMode(gridlistPlayers, 1) -- So can select many players
for _, players in ipairs(getElementsByType("player")) do  
for _, players in ipairs(getElementsByType("player")) do  
  local row = guiGridListAddRow(gridlistPlayers)
local row = guiGridListAddRow(gridlistPlayers)
  guiGridListSetItemText(gridlistPlayers, row, 1, getPlayerName(players), false, false)
guiGridListSetItemText(gridlistPlayers, row, 1, getPlayerName(players), false, false)
end  
end  
buttonSelectedPlayer = guiCreateButton(9, 227, 272, 20, "Selected", false, playerWindow)
buttonSelectedPlayer = guiCreateButton(9, 227, 272, 20, "Selected", false, playerWindow)


-- Gui click
function seeSelected()
addEventHandler("onClientGUIClick", getRootElement(), function()
local selected = guiGridListGetSelectedItems(gridlistPlayers)
  if source == buttonSelectedPlayer then
for i, data in ipairs(selected) do -- Loops through all selected items
      if #guiGridListGetSelectedItems(gridlistPlayers) > 0 then
outputChatBox("Row: "..data["row"].." Column: "..data["column"]) -- And shows you the column and row ID of all you have selected
          outputChatBox("Yes")
--outputChatBox(guiGridListGetItemText(gridlistPlayers, data["row"], 0)) -- Disabled as this should show player name but for some reason it shows blank string.
      else
end
          outputChatBox("No")
end
      end  
addEventHandler("onClientGUIClick", buttonSelectedPlayer, seeSelected, false)
  end  
end)
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 15:37, 3 February 2018

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

Syntax

table guiGridListGetSelectedItems ( element 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 in this 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
    },
    ...
}


if everything was successful or false if invalid arguments were passed.

Example

-- This example creates a grid list of all players, clicking "Selected" button will then use guiGridListGetSelectedItems to show all selected items.
playerWindow = guiCreateWindow(526, 230, 291, 284, "", false)
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 
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("Row: "..data["row"].." Column: "..data["column"]) -- And shows you the column and row ID of all you have selected
		--outputChatBox(guiGridListGetItemText(gridlistPlayers, data["row"], 0)) -- Disabled as this should show player name but for some reason it shows blank string.
	end
end
addEventHandler("onClientGUIClick", buttonSelectedPlayer, seeSelected, false)

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