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

rad tree is not getting refreshed

6 Answers 86 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Puja
Top achievements
Rank 1
Puja asked on 15 Mar 2012, 08:43 AM
I am binding my Rad TreeView in Silverlight to Dictionary type everything is working fine, but after adding new item in code behind to the dictionary the tree is not getting refreshed, I have called the NotifyPropertyChanged, after that it is again going to get the property also, but its not refreshing the tree, do I need to do some extra steps to refresh?. Anyone please help ASAP.

6 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 15 Mar 2012, 11:11 AM
Hi Puja,

 RadTreeView must be bound to collection that implements the INotifyCollectionChanged changed interface - for example the ObservableCollection<>. You can bind your tree to ObservableCollection, created like so -
collection = new ObservableCollection<DataItem>(this.dictionary.Values as IEnumerable<DataItem>)
Is this suitable for you?

Kind regards,
Petar Mladenov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Puja
Top achievements
Rank 1
answered on 16 Mar 2012, 12:06 PM
Hello Petar Mladenov,


Thanks for your quick reply, it worked out now the tree is getting refreshed :). But now I have more issue I have defined a context menu to the node, I am tryiyng to get the Parent RadTreeViewItem but its not getting that, The code i have written to get that is as below,
private void OnContextMenu_Click(object sender, RadRoutedEventArgs args)
  {
   // Get the clicked context menu item
   RadMenuItem senderItem = sender as RadMenuItem;
   // Find the tree item that is associated with the clicked context menu item
   RadTreeViewItem senderFolder = senderItem.ParentOfType<RadTreeViewItem>();
   }
   
   but here senderFolder is null. So I am not able to get the Item.
   
Thanks ,
Puja
0
Petar Mladenov
Telerik team
answered on 21 Mar 2012, 07:46 AM
Hello Puja,

 The best way to get a RadTreeViewItem clicked when opening a RadContextMenu is to use the Opened event of the ContextMenu and the event args like so:

private void RadContextMenu_Opened(object sender, RoutedEventArgs e)
        {
            RadTreeViewItem item = radContextMenu.GetClickedElement<RadTreeViewItem>();
Furthermore, the best way to define ContextMenu in RadTreeView in databinding sceanarios is to use it like a Content of the RadTreeView:
<telerik:RadTreeView x:Name="radTreeView"
                                ItemTemplateSelector="{StaticResource myTemplateSelector}"
                                ItemContainerStyle="{StaticResource treeViewStyle}">
 
               <telerik:RadContextMenu.ContextMenu>
                   <telerik:RadContextMenu x:Name="radContextMenu"
                                           Opened="RadContextMenu_Opened"
                                           ItemTemplate="{StaticResource contextMenuItemTemplate}"
                                           ItemContainerStyle="{StaticResource contextMenuItemStyle}" />
               </telerik:RadContextMenu.ContextMenu>
 
           </telerik:RadTreeView>
Please check out this demo where these code snippets are used.
You may also find this sample useful too.

All the best,
Petar Mladenov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Puja
Top achievements
Rank 1
answered on 21 Mar 2012, 10:51 AM
Hello Petar Mladenov,

 Thanks for the reply, but as i think it will add the context menu to all nodes under the tree and I want to add the context menu only to some selected items.
0
Petar Mladenov
Telerik team
answered on 21 Mar 2012, 02:08 PM
Hi Puja,

 I understand. So, can you please confirm that the suggested approach works in your scenario?

Greetings,
Petar Mladenov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Puja
Top achievements
Rank 1
answered on 26 Mar 2012, 08:55 AM
Hello Petar Mladenov,

Hey Thanks,  its working. :) otherwise I was searching for the parent OfType RadTreeViewItem which was taking time.
.
Tags
TreeView
Asked by
Puja
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Puja
Top achievements
Rank 1
Share this question
or