• How to get 1st line selected on DListView ?
    4 replies, posted
I tried some code to get work SelectFirstItem() but nothing seem to work on my code. ( I think is something wrong between the line 43 - 50 ) I have stack overflow in error. Some one can explain me how work the SelectFirstItem() with DListView ? Thanks in avance. [lua]if CLIENT then function DCustomAmmoMenu() local DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself DermaPanel:SetPos( 50,50 ) -- Position on the players screen DermaPanel:SetSize( 400, 380 ) -- Size of the frame DermaPanel:SetTitle( " | M.A.W.C. | | Menu Ammo and Weapons Customizer |" ) -- Title of the frame DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) -- Draggable by mouse? DermaPanel:ShowCloseButton( true ) -- Show the close button? DermaPanel:MakePopup() -- Show the frame local SomeCollapsibleCategory = vgui.Create("DCollapsibleCategory", DermaPanel) SomeCollapsibleCategory:SetPos( 25,70 ) SomeCollapsibleCategory:SetSize( 350, 50 ) SomeCollapsibleCategory:SetExpanded( 1 ) SomeCollapsibleCategory:SetLabel( " Player : " ) CategoryList = vgui.Create( "DPanelList" ) CategoryList:SetAutoSize( false ) CategoryList:SetSize( 350, 257 ) CategoryList:EnableHorizontal( false ) CategoryList:EnableVerticalScrollbar( true ) SomeCollapsibleCategory:SetContents( CategoryList ) -- Add our list above us as the contents of the collapsible category local ListView1Border = vgui.Create( "DPanel", CategoryList ) ListView1Border:SetPos( 9, 9 ) ListView1Border:SetSize( 142, 239 ) ListView1Border.Paint = function() -- Paint function surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel surface.DrawRect( 0, 0, ListView1Border:GetWide(), ListView1Border:GetTall() ) -- Draw the rect end local DermaWeaponsListView = vgui.Create("DListView") DermaWeaponsListView:SetParent(CategoryList) DermaWeaponsListView:SetPos( 10, 10) DermaWeaponsListView:SetSize(140, 237) DermaWeaponsListView:SetMultiSelect(false) DermaWeaponsListView:AddColumn("Weapons Name") -- Add column DermaWeaponsListView.OnRowSelected = function(panel , line) DermaWeaponsListView:SelectFirstItem( line.Sorted[1] ) local LineSelect = DermaWeaponsListView:GetLine(line):GetValue(1) LabelNameSwep.Paint = function() LabelNameSwep:SetText(LineSelect) end end for k, v in ipairs(LocalPlayer():GetWeapons()) do DermaWeaponsListView:AddLine(v:GetClass()) -- Add lines end -- Icons stuff -- local Picture1Border = vgui.Create( "DPanel", CategoryList ) Picture1Border:SetPos( 203, 23 ) Picture1Border:SetSize( 89, 89 ) Picture1Border.Paint = function() -- Paint function surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel surface.DrawRect( 0, 0, Picture1Border:GetWide(), Picture1Border:GetTall() ) -- Draw the rect end WepPicture = vgui.Create("DImage", CategoryList) WepPicture:SetSize( 85, 85 ) WepPicture:SetPos( 205, 25 ) WepPicture:SetImage( "VGUI/entities/weapon_staff" ) local PictureBottomBorder = vgui.Create( "DPanel", CategoryList ) PictureBottomBorder:SetPos( 203, 93 ) PictureBottomBorder:SetSize( 89, 19 ) PictureBottomBorder.Paint = function() surface.SetDrawColor( 0, 0, 0, 225 ) surface.DrawRect( 0, 0, PictureBottomBorder:GetWide(), PictureBottomBorder:GetTall() ) -- Draw the rect end LabelNameSwep = vgui.Create("DLabel", CategoryList) LabelNameSwep:SetPos( 210 , 91 ) end concommand.Add("DCustomAM",DCustomAmmoMenu) -- Nothing here it's just section for model info Swep -- function GetStuffWeapons(ply) for k, v in pairs(ply:GetWeapons()) do print( v:GetModel() ) end end concommand.Add("GetStuffW",GetStuffWeapons) --------------------------------------------------------- end[/lua]
-snip-
[URL="http://wiki.garrysmod.com/?title=DListView.GetSelected"]This [/URL]returns a table. To get the first value, use [1] obviously.
I'm not sure about the [1] but can you tell me if i'm in the good way ? [lua]DermaWeaponsListView.OnRowSelected = function(panel , line) DermaWeaponsListView:GetSelected(1) local LineSelect = DermaWeaponsListView:GetLine(line):GetValue(1) LabelNameSwep.Paint = function() LabelNameSwep:SetText(LineSelect) end end[/lua]
DListView.GetSelected() does not take arguments. So no, it won't be GetSelected(1). Think of it like this: [lua]local x = DermaWeaponsListView:GetSelected() local item = x[1] -- is the same as local item = DermaWeaponsListView:GetSelected()[1][/lua]
Sorry, you need to Log In to post a reply to this thread.