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

TreeView Items Clear

5 Answers 86 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Chandi
Top achievements
Rank 1
Chandi asked on 25 Jan 2011, 01:10 PM
Hi,

1. I Loaded data to a radtreeview in button click event.
2. In button click event I clear nodes as follow before load to the data to a radtreeview.
        RadTreeView1.Items.Clear();
3. But it gives error "The name already exist in the RadTreeView"

How can I solve this problem.

Thank You,
Chandi

5 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 25 Jan 2011, 03:29 PM
Hi Chandi,

Could you please send us a runnable sample cause we are unable to reproduce such issue in our environment? Thank you for your cooperation in advance.

Best wishes,
Petar Mladenov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Chandi
Top achievements
Rank 1
answered on 26 Jan 2011, 05:46 AM
Hi Petar Mladenov,

I uploaded my sample application in following location.
http://www.kandysoftglobal.com/publicshare/SampleApp.zip


Following area the steps you have to follow to reproduce my error.
1. Click "Load Tree" button
2. Select node and mouse right click.
3. Click "Delete" in context menu
4. After delete from treeview, again click "Load Tree" button. Then error will come.

Thank You,
Best Regards,
Chandi
0
Petar Mladenov
Telerik team
answered on 27 Jan 2011, 03:04 PM
Hello Chandi,

This problem occurs because you are trying to add an items with a Names that already occur in the Silverlight Namescope. Do you actually need these names? You can use Headers an you won't get such exceptions:

private void AddTreeViewItems()

{

   RadTreeViewItem category = new RadTreeViewItem();

   category.Header = "Category1";

   category.Foreground = new SolidColorBrush( Colors.Green );

   radTreeView.Items.Add( category );

     

   // Adding child items

   RadTreeViewItem product = new RadTreeViewItem();

   product.Header = "Product1.1";

   category.Items.Add( product );

   product = new RadTreeViewItem();

   product.Header = "Product1.1";

   category.Items.Add( product );

   .....

I highly recommend you to use a ViewModel class for your treeview. You can work with the ViewModel and rebind the tree when reload operations are needed. Feel free to ask if you need further assistance.

Greetings,
Petar Mladenov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Chandi
Top achievements
Rank 1
answered on 09 Feb 2011, 07:34 AM
Hi Petar Mladenov,

First, I thank you very much for your reply.

I tried samples with ViewModel class and treeview was a one level treeview.
But in my case treeview is dynamic level treeview. I exactly don't know the number of levels in tree view as it is dynamic level treeview.
Still I couldn't do this with databinding.
Can you help me please.
If you can provide a sample it will be very helpfull.

Thank You,
Best Regards,
Chandi


0
Petar Mladenov
Telerik team
answered on 10 Feb 2011, 05:02 PM
Hello Chandi,

I prepared a sample for you showing how to use HierarhicalDataTemplate. Since the Business Item ("DataItem") 's children collection is populated with items of the same type, you just need one Hierarchical template. You can find more info on  this topic here. Feel free to ask if you need further info.

Greetings,
Petar Mladenov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
TreeView
Asked by
Chandi
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Chandi
Top achievements
Rank 1
Share this question
or