Click here to Skip to main content
12,358,242 members (69,239 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

31.6K views
1 download
3 bookmarked
Posted

Expanding a TreeView to a specific node in WPF

, 13 Jan 2010 CPOL
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

You may also be interested in...

Comments and Discussions

 
QuestionSalam Pin
behrang136030-Jul-12 3:02
memberbehrang136030-Jul-12 3:02 
GeneralReason for my vote of 4 helpfull.. Pin
Mir Anas8-Aug-11 19:25
memberMir Anas8-Aug-11 19:25 
GeneralReason for my vote of 4 it's helpful! thanks! Pin
liwenjiede29-Dec-10 20:37
memberliwenjiede29-Dec-10 20:37 
GeneralClose Nodes Pin
aspdotnetdev18-Jan-10 15:06
memberaspdotnetdev18-Jan-10 15:06 
GeneralRe: Close Nodes Pin
_Mohammad_18-Jan-10 20:28
member_Mohammad_18-Jan-10 20:28 
GeneralRe: Close Nodes Pin
flobadob197524-Oct-14 3:07
memberflobadob197524-Oct-14 3:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 14 Jan 2010
Article Copyright 2010 by Mohammad Dayyan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid