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

EntityCollection and TreeListView

3 Answers 94 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 1
Benjamin asked on 22 Feb 2013, 07:10 PM
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

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 25 Feb 2013, 09:51 AM
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.

0
Benjamin
Top achievements
Rank 1
answered on 25 Feb 2013, 11:04 AM
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

0
Benjamin
Top achievements
Rank 1
answered on 25 Feb 2013, 11:11 AM
Hey,

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

Thank tou !
Tags
TreeListView
Asked by
Benjamin
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Benjamin
Top achievements
Rank 1
Share this question
or