Click here to Skip to main content
Click here to Skip to main content

Tagged as

Expanding a TreeView to a specific node in WPF

, 13 Jan 2010
Rate this:
Please Sign up or sign in to vote.
Sometimes ago , Ive been looking for a method to expand a TreeView to a specific node in WPF.I couldn't find anything useful and eventually I have written my own :/// /// Expand a TreeView to a specific node/// /// Searching will begin...
Sometimes ago , Ive been looking for a method to expand a TreeView to a specific node in WPF.
I couldn't find anything useful and eventually I have written my own :
 
/// <summary>
/// Expand a TreeView to a specific node
/// </summary>
/// <param name="TreeViewItem">Searching will begin from this TreeViewItem</param>
/// <param name="NodeName">the name of the target node</param>
void JumpToNode(TreeViewItem tvi, string NodeName)
{
    if (tvi.Name == NodeName)
    {
        tvi.IsExpanded = true;
        tvi.BringIntoView();
        return;
    }
    else
        tvi.IsExpanded = false;
 
    if (tvi.HasItems)
    {
        foreach (var item in tvi.Items)
        {
            TreeViewItem temp = item as TreeViewItem;
            JumpToNode(temp, NodeName);
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mohammad Dayyan

Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

Comments and Discussions

 
QuestionSalam Pinmemberbehrang136030-Jul-12 3:02 
GeneralReason for my vote of 4 helpfull.. PinmemberMir Anas8-Aug-11 19:25 
GeneralReason for my vote of 4 it's helpful! thanks! Pinmemberliwenjiede29-Dec-10 20:37 
GeneralClose Nodes Pinmemberaspdotnetdev18-Jan-10 15:06 
GeneralRe: Close Nodes Pinmember_Mohammad_18-Jan-10 20:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140902.1 | Last Updated 14 Jan 2010
Article Copyright 2010 by Mohammad Dayyan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid