[Resolved] GuiTreeViewCtrl getSelectedItem returning the last item, instead of current item?
by Ted Southard · in Torque Game Engine Advanced · 06/09/2009 (2:27 pm) · 1 replies

The above shows a weird behavior with the GuiTreeViewCtrl. Basically, when I call the control's .getSelectedItem() method, it returns the previously selected item (its description shown in the text, in contrast to the currently selected item which is highlighted).
How I add the items:
//%id corresponds to the top-level folders, %name to the text name, and %text to the description //that should show up in the text on the right... SkillTree.insertItem(%id, %name, %text);
How I get the %text value above into the text on the right of the GuiTreeViewCtrl:
function SkillTree::onSelect(%id)
{
%id = SkillTree.getSelectedItem(); //Tried this in hopes that it would get me the current %id, it didn't
%text = SkillTree.getItemValue(%id);
SkillDescText.setText(%text);
}So, my question is: Am I doing that callback wrong? I'm also getting these errors in the console that sort of confuse me, with the lack of docs and even comments in code:
Tried to get the object for item 3, which is not InspectorData!
What am I doing wrong? There has to be a way to get the currently selected item in a treeview control in a simple way, without the need to pull out my freshly cut hair ;) Thanks in advance to anyone who can shed light on this!
About the author
Started with indie games over a decade ago, and now creates tools and tech for games. Currently working as a contractor for startups and game studios.
Torque 3D Owner Ted Southard
function SkillTree::onSelect(%id) { //Set %id to the current selected object, instead of what is passed, //from the list of selected items used for multiple selections %id = getWord(SkillTree.getSelectedItemList(), 0); //Grab your value from the currently selected item, and rejoice! %val = SkillTree.getItemValue(%id); }Now, because of how I'm doing this, I don't know what the effect will be on anyone trying to do things with multiple selected items. Since I'm only allowing single selections in this case, it works for that situation just fine. If I have more time some day, I'll dig back into the code and track down just why it's doing this and fix it...