• Combo Box
    3 replies, posted
I've got a combo box with all the players in the server, but I've tried so many different things with GetSelectedItem / GetSelectedItems to return the selected player. I was trying to set a variable (x) to the selected item, then use that to get the player again further down. Inefficient I know but that's how demented it became after my attempts... [lua]local DComboBox1 = vgui.Create('DComboBox', AdFrame) DComboBox1:SetSize(180, 340) DComboBox1:SetPos(60, 90) DComboBox1:EnableHorizontal(false) DComboBox1:EnableVerticalScrollbar(true) ComboBox1:SetMultiple(false) for _,ply in pairs(player.GetAll()) do DComboBox1:AddItem(ply:Nick()) end local AdModelView = vgui.Create("DModelPanel", AdFrame) for o,p in pairs(player.GetAll()) do if ((p:Nick()) == (X)) then AdModelView:SetModel(p:GetModel()) end end AdModelView:SetSize(200,200) AdModelView:SetPos(230,220)[/lua] Not entire script obviously, as it's derma.. but if you really need it I'll paste it.
To return the selected player to where?
[lua]DComboBox1:GetSelectedItems[1]:GetValue()[/lua] Is how you get the value of the first thing selected, or the only thing selected if SetMultiple is false. It's a little obscure and I wish there were an easier function, but that's how it's done as is.
[QUOTE=AngryChairR;22796596]I was trying to set a variable (x) to the selected item, then use that to get the player again further down. Inefficient I know but that's how demented it became after my attempts...[/QUOTE] Actually I'm pretty sure there's no other reliable way. [QUOTE=Entoros;22807988][lua]DComboBox1:GetSelectedItems[1]:GetValue()[/lua] Is how you get the value of the first thing selected, or the only thing selected if SetMultiple is false. It's a little obscure and I wish there were an easier function, but that's how it's done as is.[/QUOTE] I don't really understand what's hard about it. How would you make it easier? By the way, GetSelectedItems is a function, so you need to add parentheses before the [1].
Sorry, you need to Log In to post a reply to this thread.