Jump to content

Help - Grid Lists


manve1

Recommended Posts

I'm trying to make like when a person presses on vehicle called "Dune" he gets an output.

local guiVehicle = guiCreateWindow( 0.3, 0.2, 0.4, 0.6, 'Vehicles', true ) 
local gridVehicles = guiCreateGridList( 0.05, 0.1, 0.5, 0.825, true, guiVehicle ) 
  
addEventHandler('onClientResourceStart', resourceRoot, 
function() 
local hColumn = guiGridListAddColumn( gridVehicles, 'Vehicles', 0.85 ) 
if ( hColumn ) then 
local hRow = guiGridListAddRow( gridVehicles ) 
local dune = guiGridListSetItemText ( gridVehicles, hRow, hColumn, 'Dune', false, false ) 
    addEventHandler('onClientGUIClick', gridVehicles, 
    function() 
        if ( guiGridListGetSelectedItem ( gridVehicles ) == 'Dune' ) then 
        outputChatBox( 'You pressed on dune.', 255, 255, 255 ) 
        end 
    end 
    ) 
end 
end 
) 

The problem is, i can't really work out how to make it.

Link to comment

That's because guiGridListGetSelectedItem returns the row and column index, not the text of it. For that you must use: guiGridListGetItemText.

addEventHandler ( 'onClientResourceStart', resourceRoot, 
    function ( ) 
        local guiVehicle = guiCreateWindow( 0.3, 0.2, 0.4, 0.6, 'Vehicles', true ) 
        local gridVehicles = guiCreateGridList( 0.05, 0.1, 0.5, 0.825, true, guiVehicle ) 
        local hColumn = guiGridListAddColumn ( gridVehicles, 'Vehicles', 0.85 ) 
        if ( hColumn ) then 
            local hRow = guiGridListAddRow ( gridVehicles ) 
            guiGridListSetItemText ( gridVehicles, hRow, hColumn, 'Dune', false, false ) 
            addEventHandler ( 'onClientGUIClick', gridVehicles, 
                function ( ) 
                    local row, col = guiGridListGetSelectedItem ( source ) 
                    if ( row and col and row ~= -1 and col ~= -1 ) then 
                        local name = guiGridListGetItemText ( source, row, hColumn ) 
                        if ( name == 'Dune' ) then 
                            outputChatBox ( 'You pressed on dune.', 255, 255, 255 ) 
                        end 
                    end 
                end 
                ,false 
            ) 
        end 
    end 
) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...