This is a migrated thread and some comments may be shown as answers.

Image path and BringPathIntoView on Treeview

5 Answers 117 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 06 Sep 2011, 01:33 AM
I am fairly new to WPF and have not mastered MVVm so I'm building my treeview manually like so:

private void BindTreeToZipCodes(RadTreeViewItem parentNode)
        {
  
            if (parentNode == null)
            {
                trvZipCodes.Items.Clear();
  
                List<State> _states = StateService.GetActive();
  
                foreach (State _state in _states)
                {
                    RadTreeViewItem node = new RadTreeViewItem() { Header = _state.StateDescription };
                    node.DefaultImageSrc = "Resources/folder.png";
  
                    node.Tag = "State";
                    if (_state.StateCode == _selectedDealer.StateCode)
                    {
                        node.IsExpanded = true;
                        node.IsSelected = true;
                        _selectedPath = _state.StateDescription;
                    }
                    else
                    {
                        node.IsExpanded = false;
                    }
                    trvZipCodes.Items.Add(node);
  
                    //call recursively to add zip parts
                    BindTreeToZipCodes(node);
                }
            }
            else //parent node is not null - what level is it
            {
                if (((string)parentNode.Tag) == "State")
                {
                    List<ZipCodePart> _zipParts = ZipCodePartService.GetForState(parentNode.Header.ToString().Substring(0, 2));
                    foreach (ZipCodePart _zipPart in _zipParts)
                    {
                        RadTreeViewItem node = new RadTreeViewItem() { Header = _zipPart.ZipPart };
                        node.Tag = "ZipPart";
                        parentNode.Items.Add(node);
                    }
                    if (parentNode.IsSelected == true)
                    {
                        _selectedPath += " | " + _zipParts[_zipParts.Count - 1].ZipPart;
                    }
                }
            }
  
        }

The image file for the state does not load despite it being in the relative path in the project.  Does it ned to be loaded in as a resource somehow rather than just specifying the relative path? 

Also what is the format of the path when bringing a TreeViewItem into view (auto scrolling) in a non-bound scenario like this, when there is more than one level involved?  I thought I saw somewhere to separate the levels items with a " | " but it doesn't seem to work.

as in:

BindTreeToZipCodes(null);
  
trvZipCodes.BringPathIntoView(_selectedPath);

Thanks,
Jonathan

5 Answers, 1 is accepted

Sort by
0
Jonathan
Top achievements
Rank 1
answered on 06 Sep 2011, 01:59 AM
Hi I added a '/' at the start of the image path name and that works fine but I'd stil like to know the format fo the path when bringing a TreeViewItem that is mutiple levels deep into view in a scrolling treeview

Thanks
Jonathan
0
Kiril Stanoev
Telerik team
answered on 08 Sep 2011, 01:11 PM
Hello Jonathan,

Please take a look at the attached project which demonstrates bringing a path into view in a databound scenario. The approach is very similar in a non-databound scenario. The project has been created following the blog post bellow:

http://blogs.telerik.com/silverlightteam/posts/11-01-12/treeview-bringintoview.aspx

Give it a try and let me know if it helps.

Best wishes,
Kiril Stanoev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Tessa
Top achievements
Rank 1
answered on 05 Aug 2014, 04:01 PM
Hi, 

Have you got a VB.NET version of the example for this please. 

Thanks
Tessa
0
Martin Ivanov
Telerik team
answered on 08 Aug 2014, 05:58 AM
Hello Tessa,

You can use a code converter to translate examples from C# to VB.NET. We have a two-way (C#, VB.NET) converter that you can use if you like.

For your convenience I prepared and attached a version of the project from the Kiril's reply in VB.NET.

I hope this helps.

Regards,
Martin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Tessa
Top achievements
Rank 1
answered on 26 Aug 2014, 01:13 PM
Thanks very much
Tags
TreeView
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Jonathan
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Tessa
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or