Smart UI Components & Libraries – Grid, Scheduler, Gantt, Kanban for Angular, React, Next.js, Vue, Blazor, JavaScript › Forums › General Discussions › Menu & Tree › How to Smart.Tree get selection by value › Reply To: How to Smart.Tree get selection by value
		June 30, 2021 at 1:14 pm
		
		#101957
		
		
		
	
Member
		
		
	Hi Sebastian Calvo,
I have created a code example which  showcases how to get the selectedIndexes when you have set the valueMember of the SmartTree.
       selectedItems =  [];
	getItems (){
		let selected= this.tree.current.selectedIndexes;
		this.selectedItems = [];
		for (let i =0; i < selected.length; i++) {
			this.selectedItems.push(this.tree.current.getItem(selected[i]));
		}
		Promise.all(this.selectedItems).then((values) => {
			this.selectedItems = values;
		});
	}
	expandItem () {
		if (!this.selectedItems[0].expanded){
			this.tree.current.expandItem(this.selectedItems[0], true)
		}
	}
	render() {
		return (
			<div>
				<Tree id="tree1" ref={this.tree} scrollMode="scrollbar" className="animation" selectionMode="oneOrMany"
					showLines dataSource={this.treeDataSource} displayMember="label" valueMember="value"></Tree>
        <button onClick={this.getItems.bind(this)}> Get selected items</button>
		<button onClick={this.expandItem.bind(this)}> Expand item</button>
      </div>
		);
	}
}In this code snippet also showcases a simple way to manage expanded and checked items.
Let me know if that works for you!
Please, do not hesitate to contact us if you have any additional questions.
Best regards,
Yavor Dashev
Smart UI Team
https://www.htmlelements.com/