This question is locked. New answers and comments are not allowed.
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
0
Hi Puja,
Petar Mladenov
the Telerik team
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?
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
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
Hello Puja,
Furthermore, the best way to define ContextMenu in RadTreeView in databinding sceanarios is to use it like a Content of the 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
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>();
<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>
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.
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
Hi Puja,
Petar Mladenov
the Telerik team
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.
.
Hey Thanks, its working. :) otherwise I was searching for the parent OfType RadTreeViewItem which was taking time.
.