GuiGridListGetSelectedItems: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 32: Line 32:
==Example==
==Example==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Todo...
playerWindow = guiCreateWindow(526, 230, 291, 284, "", false)
guiWindowSetSizable(playerWindow, false)
 
gridlistPlayers = guiCreateGridList(9, 23, 272, 201, false, playerWindow)
guiGridListAddColumn(gridlistPlayers, "Players", 0.9)
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)
buttonClosePlayer = guiCreateButton(9, 254, 272, 20, "Close", false, playerWindow)
 
addEventHandler("onClientGUIClick", getRootElement(), function()
  if source == buttonSelectedPlayer then
      if #guiGridListGetSelectedItems(gridlistPlayers) > 0 then
          outputChatBox("Yes")
      else
          outputChatBox("No")
      end
  end
end)
</syntaxhighlight>
</syntaxhighlight>



Revision as of 11:29, 4 January 2017

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

playerWindow = guiCreateWindow(526, 230, 291, 284, "", false)
guiWindowSetSizable(playerWindow, false)

gridlistPlayers = guiCreateGridList(9, 23, 272, 201, false, playerWindow)
guiGridListAddColumn(gridlistPlayers, "Players", 0.9)
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)
buttonClosePlayer = guiCreateButton(9, 254, 272, 20, "Close", false, playerWindow) 

addEventHandler("onClientGUIClick", getRootElement(), function()
   if source == buttonSelectedPlayer then 
       if #guiGridListGetSelectedItems(gridlistPlayers) > 0 then 
          outputChatBox("Yes")
       else
          outputChatBox("No")
       end 
   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