Jump to content

gridlist problem


Tox

Recommended Posts

Posted

hi there, i'm having a problem with gridlist. hope you can help. i want to order lists by column but it starts on the next row every different column and it shows something like this; bbdd9d20bc.jpg

here's my part of code;

  
  
local wepsTbl = { 
    --wep name, wep id 
    [1] = {{"Deagle", 24}, {"Pistol",22},{"Silenced",23}}, 
    [2] = {{"Shotgun",25}, {"Spaz-12",27}, {"Sawed-off",26}}, 
    [3] = {{"Uzi",28},{"Tec-9",32},{"MP5",29}}, 
    [4] = {{"M4",31},{"AK47",30}}, 
    [5] = {{"Country Rifle",33}, {"Sniper Rifle",34}}, 
    [6] = {{"RPG",35},{"Heat-Seaking RPG",36},{"Flamethrower",37},{"Minigun",38},{"Purple Dildo",10},{"Short Dildo",11}, {"Vibrator",12}, {"Flowers",14}, {"Cane",15}}, 
    [7] = {{"Golf Club",2},{"Nightstick",3},{"Knife",4},{"Baseball Bat",5},{"Shovel",6},{"Pool Cue",7},{"Katana",8},{"Chainsaw",9}} 
} 
  
    for k,_ in ipairs (wepsTbl) do 
            for __,val in ipairs (wepsTbl[k]) do  
                local wepRow = guiGridListAddRow (wepGrid) 
                guiGridListSetItemText (wepGrid,wepRow,k,val[1],false,false) 
                guiGridListSetItemData (wepGrid,wepRow,k,val[2]) 
                outputChatBox(wepRow) 
            end  
    end 

Posted

Define the column ID for each category, then add the rows to only that category.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Define the column ID for each category, then add the rows to only that category.

so you mean, i should do it without a loop? e.g rowHandgun = ... rowShotgun = ...

Posted

You have to use guiGridListSetSelectionMode.

I've redesigned your table, it's easier to edit this way.

By the way, I created a grid list for testing, it's part of the code, you should remove it and apply the selection mode to your grid list.

local wepsTbl = 
    { 
        { 
            category = "Handguns", 
            weapons = 
                { 
                    { name = "Deagle", id = 24 }, 
                    { name = "Pistol", id = 22 }, 
                    { name = "Silenced", id = 23 } 
                } 
        }, 
  
        { 
            category = "Shotguns", 
            weapons = 
                { 
                    { name = "Shotgun", id = 25 }, 
                    { name = "Spaz-12", id = 27 }, 
                    { name = "Sawed-off", id = 26 } 
                } 
        }, 
  
        { 
            category = "SMG", 
            weapons = 
                { 
                    { name = "Uzi", id = 28 }, 
                    { name = "Tec-9", id = 32 }, 
                    { name = "MP5", id = 29 } 
                } 
        }, 
  
        { 
            category = "Assault Rifles", 
            weapons = 
                { 
                    { name = "M4", id = 31 }, 
                    { name = "AK47", id = 30 } 
                } 
        }, 
  
        { 
            category = "Rifles", 
            weapons = 
                { 
                    { name = "Country Rifle", id = 33 }, 
                    { name = "Sniper Rifle", id = 34 } 
                } 
        }, 
  
        { 
            category = "Heavy", 
            weapons = 
                { 
                    { name = "RPG", id = 35 }, 
                    { name = "Heat-Seeking RPG", id = 36 }, 
                    { name = "Flamethrower", id = 37 }, 
                    { name = "Minigun", id = 38 } 
                } 
        }, 
  
        { 
            category = "Melee", 
            weapons = 
                { 
                    { name = "Purple Dildo", id = 10 }, 
                    { name = "Short Dildo", id = 11 }, 
                    { name = "Vibrator", id = 12 }, 
                    { name = "Flowers", id = 14 }, 
                    { name = "Cane", id = 15 }, 
                    { name = "Golf Club", id = 2 }, 
                    { name = "Nightstick", id = 3 }, 
                    { name = "Knife", id = 4 }, 
                    { name = "Baseball Bat", id = 5 }, 
                    { name = "Shovel", id = 6 }, 
                    { name = "Pool Cue", id = 7 }, 
                    { name = "Katana", id = 8 }, 
                    { name = "Chainsaw", id = 9 } 
                } 
        } 
    } 
  
wepGrid = guiCreateGridList(0.32, 0.25, 0.30, 0.27, true) -- TEST GRID LIST 
guiGridListSetSelectionMode ( wepGrid, 2 ) 
  
for _, data in ipairs ( wepsTbl ) do 
    local column = guiGridListAddColumn ( wepGrid, data.category, 0 ) 
    for index, weapon in ipairs ( data.weapons ) do 
        guiGridListAddRow ( wepGrid ) 
        guiGridListSetItemText ( wepGrid, index, column, weapon.name, false, false ) 
        guiGridListSetItemData ( wepGrid, index, column, weapon.id ) 
    end 
    guiGridListAutoSizeColumn ( wepGrid, column ) 
end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
You have to use guiGridListSetSelectionMode.

I've redesigned your table, it's easier to edit this way.

By the way, I created a grid list for testing, it's part of the code, you should remove it and apply the selection mode to your grid list.

local wepsTbl = 
    { 
        { 
            category = "Handguns", 
            weapons = 
                { 
                    { name = "Deagle", id = 24 }, 
                    { name = "Pistol", id = 22 }, 
                    { name = "Silenced", id = 23 } 
                } 
        }, 
  
        { 
            category = "Shotguns", 
            weapons = 
                { 
                    { name = "Shotgun", id = 25 }, 
                    { name = "Spaz-12", id = 27 }, 
                    { name = "Sawed-off", id = 26 } 
                } 
        }, 
  
        { 
            category = "SMG", 
            weapons = 
                { 
                    { name = "Uzi", id = 28 }, 
                    { name = "Tec-9", id = 32 }, 
                    { name = "MP5", id = 29 } 
                } 
        }, 
  
        { 
            category = "Assault Rifles", 
            weapons = 
                { 
                    { name = "M4", id = 31 }, 
                    { name = "AK47", id = 30 } 
                } 
        }, 
  
        { 
            category = "Rifles", 
            weapons = 
                { 
                    { name = "Country Rifle", id = 33 }, 
                    { name = "Sniper Rifle", id = 34 } 
                } 
        }, 
  
        { 
            category = "Heavy", 
            weapons = 
                { 
                    { name = "RPG", id = 35 }, 
                    { name = "Heat-Seeking RPG", id = 36 }, 
                    { name = "Flamethrower", id = 37 }, 
                    { name = "Minigun", id = 38 } 
                } 
        }, 
  
        { 
            category = "Melee", 
            weapons = 
                { 
                    { name = "Purple Dildo", id = 10 }, 
                    { name = "Short Dildo", id = 11 }, 
                    { name = "Vibrator", id = 12 }, 
                    { name = "Flowers", id = 14 }, 
                    { name = "Cane", id = 15 }, 
                    { name = "Golf Club", id = 2 }, 
                    { name = "Nightstick", id = 3 }, 
                    { name = "Knife", id = 4 }, 
                    { name = "Baseball Bat", id = 5 }, 
                    { name = "Shovel", id = 6 }, 
                    { name = "Pool Cue", id = 7 }, 
                    { name = "Katana", id = 8 }, 
                    { name = "Chainsaw", id = 9 } 
                } 
        } 
    } 
  
wepGrid = guiCreateGridList(0.32, 0.25, 0.30, 0.27, true) -- TEST GRID LIST 
guiGridListSetSelectionMode ( wepGrid, 2 ) 
  
for _, data in ipairs ( wepsTbl ) do 
    local column = guiGridListAddColumn ( wepGrid, data.category, 0 ) 
    for index, weapon in ipairs ( data.weapons ) do 
        guiGridListAddRow ( wepGrid ) 
        guiGridListSetItemText ( wepGrid, index, column, weapon.name, false, false ) 
        guiGridListSetItemData ( wepGrid, index, column, weapon.id ) 
    end 
    guiGridListAutoSizeColumn ( wepGrid, column ) 
end 

much appreciated, thanks a lot. guess the problem was defining rows

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...