We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

FInd TreeViewItemAdv by header/tag/name


I need to add new child Items to my TreeViewAdv according to the existing items name/header/tag.

for example I've added this item:

TreeViewItemAdv tvi = new TreeViewItemAdv()
{
Header ="Item1",
Tag = "Item1_Tag" + r[2].ToString(),
IsExpanded = true

};

myTree.Items.Add(tvi);

how do I than search for this Item in a loop, and match it's name/header/tag to an exisiting string?


I want to match a string to an existing item's header/tag/name and if a match was found add a child item to this item

thanks








1 Reply

KT Karthika T B Syncfusion Team May 18, 2011 07:21 AM UTC

Hi Assaf,

Thanks for choosing Syncfusion products.

We have created a simple sample based on your requirement and the sample can be downloaded from the following location:

Sample: http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=treeview5-7830128.zip

We have illustrated about the SearchItemByPath Method below:

New method ' SearchItemByPath ' has been provided to search the items by providing treeviewitem header path and final return value of this method is the treeviewitem which has been searched.

Overloaded Methods of SearchItemByPath :

1) SearchItemByPath(string path, char pathseperator)

- where path can be defined as 'Well1:Run1' where Well1 is first level TreeViewItem Header and Run1 is the next level TreeViewItem Header which is the child of Well1 and charseperator is ':'.

2) SearchItemByPath(string path, char pathseperator, bool IsSelected)

- Similar to first method which returns the treeviewitem of Run1 and the third bool parameter decides the treeviewitem to be selected or not.

3) SearchItemByPath(string path, char pathseperator, string propertyname)

- This method is also similar to first method but this method used to search when treeviewitem are added as collection objects and binded to Itemsource. Here instead of Header you can specify the value of object as path. For example Well is the class with Name and Description and these object has been binded as treeviewitem then you can mention the path hierarchy using name or description value if name is used for Path then that corresponding third parameter should be "Name".

4) SearchItemByPath(string path, char pathseperator, string propertyname, bool IsSelected)

- Similar to third method which returns the treeviewitem and the fourth bool parameter decides the treeviewitem to be selected or not.


Please let us know if you have any questions about this.

Regards,
Karthika




treeview5_d6fe986d.zip

Loader.
Live Chat Icon For mobile
Up arrow icon