Jump to content

get selected items


Dice

Recommended Posts

  
function sendListToPlayer() 
            tbl = guiGridListGetSelectedItems ( newrlist ) 
                for k,v in pairs ( tbl ) do 
                    selName = guiGridListGetItemText ( newrlist, tbl[k].row, 1 ) 
                    selUrl = guiGridListGetItemText ( newrlist, tbl[k].row, 2 ) 
                    outputChatBox ( selName .. " " .. selUrl ) 
                end 
end 
  

example problem, when function executes

if the selName is "who" and selUrl is "where" then it ouputs

who where

who where

even though i only have one item selected. again i know why it is happening but i dont know how to fix it.

I have 2 columns and multiple rows, I want to input the items selected in a table as so. the problem is, they keep printing more than once. and the reason is , because for every item seleceted. It does guiGridListGetItemText 4 times if 2 rows are selected because ( 1 row, 1 column ) and ( 1 row, 1 column ). but I don't want it to do that. I only want it to do it once and output it once.

Link to comment

I don't know if there is better way, but this should do the job.

function sendListToPlayer() 
    local R = nil 
    for _, v in ipairs (guiGridListGetSelectedItems(newrlist)) do 
        if v.row ~= R then 
            R = v.row 
            selName = guiGridListGetItemText(newrlist, v.row, 1) 
            selUrl = guiGridListGetItemText(newrlist, v.row, 2) 
            outputChatBox(selName.." " ..selUrl) 
        end 
    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...