Getting the index of the selected tab in a DPropertySheet control...

Hey

As the title says, how can I do that? There is a “GetActiveTab()” function in the control but it returns a tab object not the index. Again the Wiki is dry on this.

Can someone help me on this?

There’s no simple way from what I can see in the code, this crude method should do it though:

[lua]
for x,obj in ipairs(panel.Items) do
if obj == panel:GetActiveTab() then
// Variable x will be the index you need.
end
end
[/lua]

I’ve been working with Derma a lot just lately and I have GCFScape’d all the relevant files for Derma onto my desktop. I suggest you do the same since it really helps to take a quick look at the source; none of it’s that complicated. The source code for all these menu objects are far more useful than documentation on them, even if the documentation was good.

Thanks.

Edit:

OK it didn’t work. There weren’t any errors but it didn’t work. The object returned from the loop isn’t equal to the selected tab. I did some debugging and this is what I got: The “panel:GetActiveTab()” returns a panel as I figured from my console but the object from the loop is a table.



3
Panel: 460F8538
table: 44602720


That’s what I got from my console. The first is the index the second is “panel:GetActiveTab()” printed and the third is the object from the loop printed.

Oops, sorry.

Here, I had another look, it uses a table to help hold multiple VGUI panels so that’s why it’s returning a table instead of the panel to compare.
[lua]
for x,obj in ipairs(panel.Items) do
if obj.Tab == panel:GetActiveTab() then
// Variable x will be the index you need.
end
end
[/lua]

Alternatively you could assign your own index variable to the panel when you add a sheet and call tab:GetPanel().
[lua]
Panel.MyIndex = 1
PropertySheet:AddSheet(“Tab 1”,Panel)
[/lua]

[lua]
local tab = PropertySheet:GetActiveTab()
local index = tab:GetPanel().MyVar
[/lua]

Thanks for the help. It works now. Thanks.

You are my fucking savior! I am making a multi-tabbed chat, and it wouldn’t have been possible without you :slight_smile:

Edit:
What the hell; I got rated dumb within the first 40 mins of posting…
Edit1:
Oh… My bad? :stuck_out_tongue: