DgsGridListGetSelectedCount: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Client function}} __NOTOC__ This function returns the items selected in the specified dgs grid list. Note that the index of row and column start from 1, which is different...")
 
No edit summary
Line 1: Line 1:
{{Client function}}
{{Client function}}
__NOTOC__
__NOTOC__
This function returns the items selected in the specified dgs grid list.
This function returns the amount of options selected in the specified dgs grid list.
 
Note that the index of row and column start from 1, which is different from [[guiGridListGetSelectedCount]].


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
table dgsGridListGetSelectedItems ( element gridList )
int guiGridListGetSelectedCount ( element gridList [, int inRow = -1, int inColumn = -1 ] )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===  
===Required Arguments===  
*'''gridList:''' The dgs grid list which selected items you want to retrieve.
*'''gridList:''' The dgs grid list whose amount of selected items you want to retrieve.
 
===Optional Arguments==
*''' inRow:''' An integer of the index of the specific row ( used to get the count of items from the specific row ).
*''' inColumn:''' An integer of the index of the specific column  ( used to get the count of items from the specific column ).


===Returns===
===Returns===
Returns a table over the selected items in the dgs grid list in this format ( the same as cegui's ) :
Returns an integer representing the amount of selected options if everything was successful or ''false'' if invalid arguments were passed.
<syntaxhighlight lang="lua">
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
    },
    ...
}
 
 
</syntaxhighlight>
if everything was successful or ''false'' if invalid arguments were passed.


==Example==
==Example==
This example creates a gridlist filled with players names then check who has the letter "a" in their name, after it selects everyone who has the letter "a" then it outputs the selected rows.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
DGS = exports.dgs
DGS = exports.dgs
-- This example creates a grid list of all players, clicking "Selected" button will then use dgsGridListGetSelectedItems to show all selected items.
gridlist = DGS:dgsCreateGridList(100,100,200,100,false)
playerWindow = DGS:dgsCreateWindow(526, 230, 291, 284, "", false)
DGS:dgsGridListAddColumn(gridlist,"Players",0.50)
gridlistPlayers = DGS:dgsCreateGridList(9, 23, 272, 201, false, playerWindow)
for i,v in ipairs(getElementsByType("player"))do
DGS:dgsGridListAddColumn(gridlistPlayers, "Players", 0.9)
DGS:dgsGridListSetItemText(gridlist,DGS:dgsGridListAddRow(gridlist),1,getPlayerName(v),false,false)
DGS:dgsGridListSetSelectionMode(gridlistPlayers, 1) -- So can select many players
end
for _, players in ipairs(getElementsByType("player")) do  
for b=0, DGS:dgsGridListGetRowCount(gridlist)do
local row = DGS:dgsGridListAddRow(gridlistPlayers)
if(string.find(DGS:dgsGridListGetItemText(gridlist,b,1),"a",1,true))then
DGS:dgsGridListSetItemText(gridlistPlayers, row, 1, getPlayerName(players))
DGS:dgsGridListSetSelectedItem(gridlist,b,1)
end  
buttonSelectedPlayer = DGS:dgsCreateButton(9, 227, 272, 20, "Selected", false, playerWindow)
 
function seeSelected()
local selected = DGS:dgsGridListGetSelectedItems(gridlistPlayers)
for i, data in ipairs(selected) do -- Loops through all selected items
outputChatBox(DGS:dgsGridListGetItemText(gridlistPlayers, data["row"], 1)) -- Shows player name of selected players
end
end
end
end
addEventHandler("onDgsMouseClick", buttonSelectedPlayer, seeSelected, false)
outputChatBox("The number of Players with 'a' in their name: "..guiGridListGetSelectedCount(gridlist)..".")
</syntaxhighlight>
</syntaxhighlight>



Revision as of 06:05, 11 July 2019

This function returns the amount of options selected in the specified dgs grid list.

Syntax

int guiGridListGetSelectedCount ( element gridList [, int inRow = -1, int inColumn = -1 ] )

Required Arguments

  • gridList: The dgs grid list whose amount of selected items you want to retrieve.

=Optional Arguments

  • inRow: An integer of the index of the specific row ( used to get the count of items from the specific row ).
  • inColumn: An integer of the index of the specific column ( used to get the count of items from the specific column ).

Returns

Returns an integer representing the amount of selected options if everything was successful or false if invalid arguments were passed.

Example

This example creates a gridlist filled with players names then check who has the letter "a" in their name, after it selects everyone who has the letter "a" then it outputs the selected rows.

DGS = exports.dgs
gridlist = DGS:dgsCreateGridList(100,100,200,100,false)
DGS:dgsGridListAddColumn(gridlist,"Players",0.50)
for i,v in ipairs(getElementsByType("player"))do
	DGS:dgsGridListSetItemText(gridlist,DGS:dgsGridListAddRow(gridlist),1,getPlayerName(v),false,false)
end
for b=0, DGS:dgsGridListGetRowCount(gridlist)do
	if(string.find(DGS:dgsGridListGetItemText(gridlist,b,1),"a",1,true))then
		DGS:dgsGridListSetSelectedItem(gridlist,b,1)
	end
end
outputChatBox("The number of Players with 'a' in their name: "..guiGridListGetSelectedCount(gridlist)..".")

See Also

Custom Cursor Functions

Multi Language Supports

Animation

3D Element

3D Interface

3D Line

3D Image

3D Text

Browser

Button

Check Box

Combo Box

Custom Renderer

Edit

Detect Area

Drag'N Drop

Grid List

Image

Memo

Menu

Label

Layout

Line

Progress Bar

Radio Button

Scale Pane

Scroll Bar

Scroll Pane

Selector

Style

Switch Button

Tab Panel

Window

Basic Shape Plugins

Circle

Quadrilateral

Rounded Rectangle

Other Plugins

Blur Box

Canvas

Chart

Color Picker

Effect 3D

Gradient

Mask

Media Browser

Nine Slice

Object Preview Supports

Paste Handler

QRCode

Remote Image

Screen Source

SVG

Tooltips

General

Check Box

Combo Box

Drag'N Drop

Edit

Grid List

Menu

Selector

Mouse

Radio Button

Switch Button

Tab

Animation

Plugin

Media

Color Picker

QRCode

Remote Image