TreeView Items Clear

6 posts, 0 answers
  1. Chandi
    Chandi avatar
    4 posts
    Member since:
    Jan 2011

    Posted 25 Jan 2011 Link to this post

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

    Posted 25 Jan 2011 Link to this post

    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>>
  3. DevCraft banner
  4. Chandi
    Chandi avatar
    4 posts
    Member since:
    Jan 2011

    Posted 25 Jan 2011 Link to this post

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

    Posted 27 Jan 2011 Link to this post

    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>>
  6. Chandi
    Chandi avatar
    4 posts
    Member since:
    Jan 2011

    Posted 09 Feb 2011 Link to this post

    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


  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 10 Feb 2011 Link to this post

    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>>
Back to Top
DevCraft banner