I've used this code to open and select arbitrary nodes in the V2 tree component. Might be portable to Flex, or not.
private function displayAndOpenNode(component:Tree, label:String, node:XMLNode) { if(node == undefined) { for(var i=0; i<component.dataProvider.childNodes.length; i++) { displayAndOpenNode(component, label, component.dataProvider.childNodes[i]); } } if(node.attributes.label == label) { var parent = node.parentNode; while(parent != undefined) { component.setIsOpen(parent, true, false, false); parent = parent.parentNode; } selectFirstChildWithData(component, node); return true; } for(var i=0; i<node.childNodes.length; i++) { if(displayAndOpenNode(component, label, node.childNodes[i]) == true) { return true; } } return false; } private function selectFirstChildWithData(component:Tree, node:XMLNode):Void { while(node.attributes.data == '') { __tree.setIsOpen(node, true, false, false); node = __tree.getNodeDisplayedAt(__tree.getDisplayIndex(node) + 1); } __tree.selectedNode = node; onChangeSelection({target:component}); } -josh On Jun 8, 2006, at 2:26p, rigidcode wrote: > > If you make a Tree, and you set it's data to an XML object: > > var tree:Tree = new Tree(); > tree.showRoot=false; > tree.labelField="@label"; > > var xml:XML = <node > > <node label="Something"> > <node label="child one"/> > <node label="another child"/> > </node> > </node>; > > tree.dataProvider =xml; > > How do you programmatically open the "Something" item? > > I've tried: > > tree.expandItem( XML(this._tree.dataProvider).node[0],true); > > tree.expandItem( XML(XML(this._tree.dataProvider).node[0]),true); > > tree.expandItem( XML(this._tree.dataProvider).elements('node') ,true); > > tree.expandItem( > XML(this._tree.dataProvider).elements('node').valueOf() ,true); > > > And I've tried tree.invalidateList(); afterwards, doesn't help. This > might be a flex bug. Has anyone programmatically selected a tree node > *without* using something like tree.selectedItem.parent? > > > > > > > > > > > ------------------------ Yahoo! Groups Sponsor -------------------- > ~--> > Protect your PC from spy ware with award winning anti spy > technology. It's free. > http://us.click.yahoo.com/97bhrC/LGxNAA/yQLSAA/nhFolB/TM > -------------------------------------------------------------------- > ~-> > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: http://www.mail-archive.com/flexcoders% > 40yahoogroups.com > Yahoo! Groups Links > > > > > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> You can search right from your browser? It's easy and it's free. See how. http://us.click.yahoo.com/_7bhrC/NGxNAA/yQLSAA/nhFolB/TM --------------------------------------------------------------------~-> -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/