EntityCollection and TreeListView

4 posts, 0 answers
  1. Benjamin
    Benjamin avatar
    24 posts
    Member since:
    Dec 2012

    Posted 22 Feb 2013 Link to this post

    Hello,

    I'am using Q1 2013 and Entity Framework.
    Th UI is not refreshed when I bound the child source to EntityCollection.
    Does the TileListView support the AssociationChanged event of EntityCollection ?

    Thank you
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 25 Feb 2013 Link to this post

    Hi,

    I am afraid that RadTreeListView can only listen for the standard .NET events such as INotifyCollectionChanged. Unfortunately, we can not tightly couple it with EntityCollection to listen specifically for this AssociationChanged event, which I even could not find on the EntityCollection class.

    Maybe this StackOverflow discussions can give you some ideas.

    Regards,
    Rossen Hristov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Benjamin
    Benjamin avatar
    24 posts
    Member since:
    Dec 2012

    Posted 25 Feb 2013 Link to this post

    Hi,

    Thanks for your help.
    The AssociationChanged event belong to the base class of EntityCollection :  RelationEnd class.
    I add a converter in order to create the ObservableCollections and make the wrap :
    public class RelatedEndToObservableCollectionConverter : IValueConverter
    {
        #region Fields
     
        private Dictionary<RelatedEnd, ObservableCollection<object>> _Dictionary;
     
        #endregion
     
        #region Constructors
     
        public RelatedEndToObservableCollectionConverter()
        {
            _Dictionary = new Dictionary<RelatedEnd, ObservableCollection<object>>();
        }
     
        #endregion
     
        #region Methods
     
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!_Dictionary.Keys.Contains(value))
            {
     
                RelatedEnd relatedEnd = (RelatedEnd)value;
                ObservableCollection<object> wraperCollection = new ObservableCollection<object>();
                this._Dictionary.Add(relatedEnd, wraperCollection);
     
                relatedEnd.AssociationChanged += relatedEnd_AssociationChanged;
     
                foreach (var item in relatedEnd)
                {
                    wraperCollection.Add(item);
                }
     
     
            }
            return _Dictionary[(RelatedEnd)value];
        }
     
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
     
        void relatedEnd_AssociationChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e)
        {
            switch (e.Action)
            {
                case System.ComponentModel.CollectionChangeAction.Add:
                    _Dictionary[(RelatedEnd)sender].Add(e.Element);
                    break;
                case System.ComponentModel.CollectionChangeAction.Refresh:
                    _Dictionary[(RelatedEnd)sender].Clear();
                    foreach (var item in (RelatedEnd)sender)
                    {
                        _Dictionary[(RelatedEnd)sender].Add(item);
                    }
                    break;
                case System.ComponentModel.CollectionChangeAction.Remove:
                    _Dictionary[(RelatedEnd)sender].Remove(e.Element);
                    break;
                default:
                    break;
            }
        }
     
        #endregion
    }

    And i use it like that :

            <telerik:RadTreeListView ItemsSource="{Binding Invoice.Chapters}" SelectedItem="{Binding SelectedItem}">
              <telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:TreeListViewTableDefinition>
                  <telerik:TreeListViewTableDefinition.ItemsSource>
                    <Binding Path="Chapters">
                      <Binding.Converter>
                        <converters:RelatedEndToObservableCollectionConverter/>
                      </Binding.Converter>
                    </Binding>
                  </telerik:TreeListViewTableDefinition.ItemsSource>
                </telerik:TreeListViewTableDefinition>
              </telerik:RadTreeListView.ChildTableDefinitions>
    ...

    I have a graphic bug in the TreeListView (please see the attached image), there are white spaces in the control.
    Does I made something wrong or does it's a bug from the TreeListView ?

    Thank you for your help

  5. Benjamin
    Benjamin avatar
    24 posts
    Member since:
    Dec 2012

    Posted 25 Feb 2013 Link to this post

    Hey,

    My bad, I just found the solution, I had to populate the ObservableCollection before subscribe to the AssociationChanged event.

    Thank tou !
Back to Top