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

RadTreeListView ContainerBinding not Binding

2 Answers 118 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
JJ Loubser
Top achievements
Rank 1
JJ Loubser asked on 15 Mar 2011, 08:44 AM
the <telerik:ContainerBinding PropertyName="IsExpanded"
                                     Binding="{Binding IsItemCollectionExpanded, Mode=TwoWay}" />
is not binding to my object for RadTreeListView, but for a RadTreeView it is working fine. Look at my code what is wrong, ive tried allot of things, what am I missing? Also tried RowDetailsTemplate="{StaticResource RootItem}" not working. Tried to manipulate the RadTreeListView nodes in code behind in my viewmodel, the container is always empty on new loads.

----------------------------- 


<telerik:HierarchicalDataTemplate x:Key="RootItem"
                                             ItemsSource="{Binding Children}"
                                                  >
                           
                    <telerik:ContainerBinding.ContainerBindings>
                        <telerik:ContainerBindingCollection>
                            <telerik:ContainerBinding PropertyName="IsExpanded"
                                     Binding="{Binding IsItemCollectionExpanded, Mode=TwoWay}" />
                        </telerik:ContainerBindingCollection>
                    </telerik:ContainerBinding.ContainerBindings>


                </telerik:HierarchicalDataTemplate>




<telerik:RadTreeListView
                                    x:Name="radTreeViewlist"
                                    BorderThickness="1"
                                    BorderBrush="Black"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch"
                                    AutoGenerateColumns="False"
                                    SelectionChanged="radTreeViewlist_SelectionChanged"
                                    IsDragDropEnabled="False"
                                    ItemsSource="{Binding SelectionList}"
                                    SelectionMode="Single"
                                    SelectionUnit="FullRow"
                                    DataLoaded="radTreeViewlist_DataLoaded"
                                    EnableRowVirtualization="True"
                                    EnableColumnVirtualization="True"
                                    ItemTemplate="{StaticResource RootItem}"
                                    >
                                     
                                <telerikNavigation:RadContextMenu.ContextMenu>
                                    <telerikNavigation:RadContextMenu x:Name="radContextMenu"
                                                  ItemTemplate="{StaticResource ContextMenuDataTemplate}"
                                                  Opened="radContextMenu_Opened"
                                                  ItemClick="radContextMenu_ItemClick"
                                                  >

                                    </telerikNavigation:RadContextMenu>
                                </telerikNavigation:RadContextMenu.ContextMenu>

                                <telerik:RadTreeListView.ChildTableDefinitions>
                                    
                                    <telerik:TreeListViewTableDefinition
                                                        ItemsSource="{Binding Children}"
                                                        >
                                        
                                    </telerik:TreeListViewTableDefinition>

                                   

                                </telerik:RadTreeListView.ChildTableDefinitions>


                                <telerik:RadTreeListView.Columns
                                    >


                                    <telerik:GridViewDataColumn CellStyle="{StaticResource GridViewCellStyle}"
                                                                DataMemberBinding="{Binding ItemName, Mode=TwoWay}"
                                                                Header="Name"   
                                                                IsReadOnly="True">
                                    </telerik:GridViewDataColumn>


                                    <telerik:GridViewDataColumn DataMemberBinding="{Binding TimePeriod.TimeQuantityTypeListItem}"
                                                Header="Type" IsReadOnly="True"/>
                                    <telerik:GridViewDataColumn DataMemberBinding="{Binding TimePeriod.TimeQuantity}"
                                                Header="Quantity"  IsReadOnly="True"/>
                                    <telerik:GridViewDataColumn DataMemberBinding="{Binding TimePeriod.StartDate}"
                                                Header="StartDate" IsReadOnly="True"/>
                                    <telerik:GridViewDataColumn DataMemberBinding="{Binding TimePeriod.EndDate}"
                                                Header="EndDate"  IsReadOnly="True"/>
                                    <telerik:GridViewDataColumn DataMemberBinding="{Binding TimePeriod.StartTime, Converter={StaticResource TimeConverters}}"
                                                Header="StartTime"  IsReadOnly="True"/>
                                    <telerik:GridViewDataColumn DataMemberBinding="{Binding TimePeriod.EndTime, Converter={StaticResource TimeConverters}}"
                                                Header="EndTime"  IsReadOnly="True"/>

                                </telerik:RadTreeListView.Columns>


                            </telerik:RadTreeListView>



----------------------------

<introduces container recycling for further improvement of speed and memory footprint> - is this the problem?



--------------------
works fine for the RadTreeView
____________
RadTreeView:


 <telerik:HierarchicalDataTemplate x:Key="RootItem"
                                              ItemsSource="{Binding Children}"
                                              >
                
                    <StackPanel Orientation="Horizontal"
                           >
                        <Image Source="{Binding ImageURL}" Width="20" Height="20" Margin=" 0,0,6,0"  />

                        <StackPanel Orientation="Horizontal"
                                Background="{Binding ViewModel, Converter={StaticResource ColorConvertersTreeItemIsNewOrgStructure}}"
                           >
                            
                            
                            <TextBlock Text="{Binding ItemName}"  
                                       VerticalAlignment="Center" />
                            <TextBlock Text="{Binding ItemPriority}"  
                                       VerticalAlignment="Center" />
                        </StackPanel>
                    </StackPanel>
                <telerik:ContainerBinding.ContainerBindings>
                    <telerik:ContainerBindingCollection>
                        <telerik:ContainerBinding PropertyName="IsExpanded"
                                     Binding="{Binding IsItemCollectionExpanded, Mode=TwoWay}" />
                    </telerik:ContainerBindingCollection>
                </telerik:ContainerBinding.ContainerBindings>


            </telerik:HierarchicalDataTemplate>


<telerikNavigation:RadTreeView x:Name="radTreeView"
                                    BorderThickness="0"
                                    BorderBrush="Black"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch"
                                    ItemsSource="{Binding OrgStructList}"
                                    ItemTemplate="{StaticResource RootItem}"
                                    Width="300"
                                    IsDragDropEnabled="True"
                                    PreviewDragStarted="radTreeView_PreviewDragStarted"
                                    DragStarted="radTreeView_DragStarted"
                                    PreviewDragEnded="radTreeView_PreviewDragEnded"
                                    DragEnded="radTreeView_DragEnded"
                                    >




                                <telerikNavigation:RadContextMenu.ContextMenu>
                                    <telerikNavigation:RadContextMenu x:Name="radContextMenu"
                                                  ItemTemplate="{StaticResource ContextMenuDataTemplate}"
                                                  Opened="radContextMenu_Opened"
                                                  >

                                    </telerikNavigation:RadContextMenu>
                                </telerikNavigation:RadContextMenu.ContextMenu>

                            </telerikNavigation:RadTreeView>




--------------

viewModel - cs.:

 private void HandleIsExpandedTreeItems(ObservableCollection<TreeViewListItem> collection, ObservableCollection<TreeViewListItem> collectionCopy)
        {
            if (collection != null && collection.Count > 0)
                foreach (var item in collection)
                    if (collectionCopy != null && collectionCopy.Count > 0)
                        foreach (var itemCopy in collectionCopy)
                        {
                            if (item.Equals(itemCopy))
                            {
                                item.IsItemCollectionExpanded = itemCopy.IsItemCollectionExpanded;                  // for items
                                if (item.IsItemCollectionExpanded)
                                { }
                                HandleIsExpandedTreeItems(item.Children, itemCopy.Children);
                                break;
                            }
                        }
        }

----------
TreeViewListItem myClass.cs:

 public class TreeViewListItem  
          {
       

        public TreeViewListItem(ObservableCollection<TreeViewListItem> theParent, object viewModel, TreeViewListItemObjectType objType, string name, string imageURL, int pId, int pPriority)
        {
            
            //Children = new ObservableCollection<TreeViewListItem>();
            parent = theParent;
            ViewModel = viewModel;
            ObjType = objType;
            ImageURL = imageURL;
            ItemName = name;
            Id = pId;
            Priority = pPriority;
        }
...
}

2 Answers, 1 is accepted

Sort by
0
JJ Loubser
Top achievements
Rank 1
answered on 15 Mar 2011, 10:52 AM
used rowloaded:

http://www.telerik.com/community/forums/silverlight/treelist/automatically-expand-all-nodes-in-radtreelistview-v2010-2-714-by-default.aspx#1562141

but get Com error...
0
JJ Loubser
Top achievements
Rank 1
answered on 15 Mar 2011, 11:03 AM
working when I update this code:

try
                                        {
                                            Row_.IsExpanded = oldRow_.IsExpanded;
                                            Row_.SetBinding(TreeListViewRow.IsExpandedProperty, new Binding()
                                                                                                {
                                                                                                  Source = item,
                                                                                                  Path = new PropertyPath("IsItemCollectionExpanded")
                                                                                                }
                                                           );
                                           
                                        }
                                        catch (Exception eeee)
                                        { }

in:

 private RadTreeListView radTreeListView_;
        private bool mTreeViewListLeftScreen = false;
        private bool mTreeViewSetAllExapnd = false;
        public void radTreeViewlist_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            if (!mTreeViewListLeftScreen)
            {
                radTreeListView_ = (RadTreeListView)sender;
                if (radTreeListView_ != null && radTreeListView_.ItemsSource != null && radTreeListView_.Items.Count > 0)
                {
                    
                    foreach (TreeViewListItem item in radTreeListView_.Items)
                    {
                        
                        if (radTreeListView_.ItemContainerGenerator.ContainerFromItem(item) != null && radTreeListView_.ItemContainerGenerator.ContainerFromItem(item) is TreeListViewRow)
                        {

                            TreeListViewRow Row_ = (TreeListViewRow)radTreeListView_.ItemContainerGenerator.ContainerFromItem(item);
                            item.IsItemCollectionExpanded = Row_.IsExpanded;
                            Row_.SetBinding(TreeListViewRow.IsExpandedProperty, new Binding()
                                                                                {
                                                                                    Source = item,
                                                                                    Path = new PropertyPath("IsItemCollectionExpanded")
                                                                                }
                                           );


                        }
                    }
                }
            }
            else
            {
                RadTreeListView radTreeListView_New = (RadTreeListView)sender;
                if (radTreeListView_New != null && radTreeListView_New.ItemsSource != null && radTreeListView_New.Items.Count > 0)
                {
                                      

                    foreach (TreeViewListItem item in radTreeListView_New.Items)
                    {
                       
                        if (radTreeListView_New.ItemContainerGenerator.ContainerFromItem(item) != null && radTreeListView_New.ItemContainerGenerator.ContainerFromItem(item) is TreeListViewRow)
                        {
                            foreach (TreeViewListItem olditem in radTreeListView_.Items)
                            {
                                if (olditem.Id == item.Id)
                                {
                                    if (radTreeListView_.ItemContainerGenerator.ContainerFromItem(olditem) != null && radTreeListView_.ItemContainerGenerator.ContainerFromItem(olditem) is TreeListViewRow)
                                    {
                                        TreeListViewRow Row_ = (TreeListViewRow)radTreeListView_New.ItemContainerGenerator.ContainerFromItem(item);
                                        TreeListViewRow oldRow_ = (TreeListViewRow)radTreeListView_.ItemContainerGenerator.ContainerFromItem(olditem);

                                        if (oldRow_.IsExpanded)
                                        {}
                                        try
                                        {
                                            Row_.IsExpanded = oldRow_.IsExpanded;
                                            Row_.SetBinding(TreeListViewRow.IsExpandedProperty, new Binding()
                                                                                                {
                                                                                                  Source = item,
                                                                                                  Path = new PropertyPath("IsItemCollectionExpanded")
                                                                                                }
                                                           );
                                           
                                        }
                                        catch (Exception eeee)
                                        { }

                                       

                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        public void radTreeViewlist_RowUnloaded(object sender, Telerik.Windows.Controls.GridView.RowUnloadedEventArgs e)
        {
           
        }


just need to upgrade this code for 3 time + loads... Remember this is in ViewModel code not code behind...
Tags
TreeListView
Asked by
JJ Loubser
Top achievements
Rank 1
Answers by
JJ Loubser
Top achievements
Rank 1
Share this question
or