Image path and BringPathIntoView on Treeview

6 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    134 posts
    Member since:
    Sep 2007

    Posted 05 Sep 2011 Link to this post

    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
  2. Jonathan
    Jonathan avatar
    134 posts
    Member since:
    Sep 2007

    Posted 05 Sep 2011 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 08 Sep 2011 Link to this post

    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 >>

  5. Tessa
    Tessa avatar
    8 posts
    Member since:
    Jul 2011

    Posted 05 Aug 2014 Link to this post

    Hi, 

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

    Thanks
    Tessa
  6. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 08 Aug 2014 Link to this post

    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.
     
  7. Tessa
    Tessa avatar
    8 posts
    Member since:
    Jul 2011

    Posted 26 Aug 2014 in reply to Martin Link to this post

    Thanks very much
Back to Top
UI for WPF is Visual Studio 2017 Ready