rad tree is not getting refreshed

7 posts, 0 answers
  1. Puja
    Puja avatar
    8 posts
    Member since:
    Jan 2012

    Posted 15 Mar 2012 Link to this post

    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.
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 15 Mar 2012 Link to this post

    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 >>
  3. DevCraft banner
  4. Puja
    Puja avatar
    8 posts
    Member since:
    Jan 2012

    Posted 16 Mar 2012 Link to this post

    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
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 21 Mar 2012 Link to this post

    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 >>
  6. Puja
    Puja avatar
    8 posts
    Member since:
    Jan 2012

    Posted 21 Mar 2012 Link to this post

    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.
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 21 Mar 2012 Link to this post

    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 >>
  8. Puja
    Puja avatar
    8 posts
    Member since:
    Jan 2012

    Posted 26 Mar 2012 Link to this post

    Hello Petar Mladenov,

    Hey Thanks,  its working. :) otherwise I was searching for the parent OfType RadTreeViewItem which was taking time.
    .
Back to Top
DevCraft banner