Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > TreeView > CollectionViewSource.GetDefaultView and hierarchical tree

Not answered CollectionViewSource.GetDefaultView and hierarchical tree

Feed from this thread
  • Dmitry Intermediate avatar

    Posted on Jan 26, 2012 (permalink)

    Hello,
    I have a Category class which contains Categories property which is a List<Category>. I use MVVM with your OpenAccess ORM. Here is a XAML markup I use to bind tree to data:
    <telerik:RadTreeView HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="CategoryTree" ItemsSource="{Binding Path=Categories}" SelectedItem="{Binding Path=CurrentCategory, Mode=TwoWay}" SelectionChanged="CategoryTree_SelectionChanged">
                                    <telerik:RadTreeView.ItemTemplate>
                                        <HierarchicalDataTemplate ItemsSource="{Binding Categories}">
                                            <TextBlock Text="{Binding Name}" />
                                        </HierarchicalDataTemplate>
                                    </telerik:RadTreeView.ItemTemplate>
                                </telerik:RadTreeView>

    In CategoryViewModel I have the following method:
    protected override void Load()
            {
                _categories = new ObservableCollection<CategoryBO>();
                foreach (Category category in _repositoryCategory.Entities.Where(p => p.ParentCategory == null))
                {
                    CategoryBO tempCategory = category;
                    if (tempCategory != null)
                    {
                        Categories.Add(tempCategory);
                    }
                }
                _categoryView = CollectionViewSource.GetDefaultView(Categories);
                OnPropertyChanged("CategoriesList");
                OnPropertyChanged("CurrentCategory");
            } and this is how I initialize a CategoryBO object:
     public static implicit operator CategoryBO(Category category)
            {
                return new CategoryBO(category);
            }
    public CategoryBO(Category category)
            {
                ID = category.CategoryID;
                ParentID = category.ParentID;
                Name = category.Name;
                foreach (ProductBO product in category.Products)
                {
                    _products.Add(product);
                }

                foreach (Category cat in category.Categories)
                {
                    _categories.Add(cat);
                }
            }
    As you can see, I iterate through root level categories and they all have a Categories property filled with data. But when I try to select child categories from tree, they select visually on the tree but SelectedItem is always null. This happens because in Load() method I have CollectionViewSource.GetDefaultView(Categories) which returns a list which contains only root categories. 
    How do get SelectedItem?
    Thank you.

    Reply

  • Dmitry Intermediate avatar

    Posted on Jan 28, 2012 (permalink)

    Anyone?

    Reply

  • Petar Petar admin's avatar

    Posted on Jan 31, 2012 (permalink)

    Hi Dmitry,

     I think I was not able to completely understand your scenario here. Are the details correctly loaded in the grid or are they missing? Furthermore can you please share with me how is your data traveling to the client side? If you are using any kind of services can you please share with us the implementation of it?

    Greetings,
    Petar
    the Telerik team

    SP1 for Q3’11 of Telerik OpenAccess ORM is available for download

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > TreeView > CollectionViewSource.GetDefaultView and hierarchical tree
Related resources for "CollectionViewSource.GetDefaultView and hierarchical tree"

WPF TreeView Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]