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

treeview clearing selected nodes

2 Answers 211 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
jack abdallah
Top achievements
Rank 1
jack abdallah asked on 11 Apr 2011, 10:31 AM
Hi
i am using telerik q3 2010 treeview for winforms

in my project i select multiple nodes in the treeview and user can select different nodes depending on his choice but it seems that the old selected nodes is not clearing and keep saving the old selected nodes
i used :
radtreeview.selectednodes.clear()
but it seems it is not clearing the selected nodes is there any code that could be used to clear selected nodes
any help is appreciated
regards,

2 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 11 Apr 2011, 03:15 PM
Hello Jack,

I don't have the older version to try, but this seems to work fine in the latest version. The RadTreeView has been overhauled by the way in Q1 2011 and is now much faster and more flexible.

Here is a very brief sample:

Designer File
partial class Form1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components;
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        Telerik.WinControls.UI.RadTreeNode radTreeNode1 = new Telerik.WinControls.UI.RadTreeNode();
        Telerik.WinControls.UI.RadTreeNode radTreeNode2 = new Telerik.WinControls.UI.RadTreeNode();
        Telerik.WinControls.UI.RadTreeNode radTreeNode3 = new Telerik.WinControls.UI.RadTreeNode();
        Telerik.WinControls.UI.RadTreeNode radTreeNode4 = new Telerik.WinControls.UI.RadTreeNode();
        Telerik.WinControls.UI.RadTreeNode radTreeNode5 = new Telerik.WinControls.UI.RadTreeNode();
        Telerik.WinControls.UI.RadTreeNode radTreeNode6 = new Telerik.WinControls.UI.RadTreeNode();
        Telerik.WinControls.UI.RadTreeNode radTreeNode7 = new Telerik.WinControls.UI.RadTreeNode();
        Telerik.WinControls.UI.RadTreeNode radTreeNode8 = new Telerik.WinControls.UI.RadTreeNode();
        this.radTreeView1 = new Telerik.WinControls.UI.RadTreeView();
        ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).BeginInit();
        this.SuspendLayout();
        // 
        // radTreeView1
        // 
        this.radTreeView1.BackColor = System.Drawing.SystemColors.Control;
        this.radTreeView1.Cursor = System.Windows.Forms.Cursors.Default;
        this.radTreeView1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.radTreeView1.Font = new System.Drawing.Font("Segoe UI", 8.25F);
        this.radTreeView1.ForeColor = System.Drawing.Color.Black;
        this.radTreeView1.Location = new System.Drawing.Point(0, 0);
        this.radTreeView1.Name = "radTreeView1";
        radTreeNode1.Expanded = true;
        radTreeNode1.Name = "Node1";
        radTreeNode2.Name = "Node5";
        radTreeNode2.Text = "Node5";
        radTreeNode1.Nodes.AddRange(new Telerik.WinControls.UI.RadTreeNode[] {
        radTreeNode2});
        radTreeNode1.Text = "Node1";
        radTreeNode3.Expanded = true;
        radTreeNode3.Name = "Node2";
        radTreeNode4.Name = "Node6";
        radTreeNode4.Text = "Node6";
        radTreeNode3.Nodes.AddRange(new Telerik.WinControls.UI.RadTreeNode[] {
        radTreeNode4});
        radTreeNode3.Text = "Node2";
        radTreeNode5.Expanded = true;
        radTreeNode5.Name = "Node3";
        radTreeNode6.Name = "Node7";
        radTreeNode6.Text = "Node7";
        radTreeNode5.Nodes.AddRange(new Telerik.WinControls.UI.RadTreeNode[] {
        radTreeNode6});
        radTreeNode5.Text = "Node3";
        radTreeNode7.Expanded = true;
        radTreeNode7.Name = "Node4";
        radTreeNode8.Name = "Node8";
        radTreeNode8.Text = "Node8";
        radTreeNode7.Nodes.AddRange(new Telerik.WinControls.UI.RadTreeNode[] {
        radTreeNode8});
        radTreeNode7.Text = "Node4";
        this.radTreeView1.Nodes.AddRange(new Telerik.WinControls.UI.RadTreeNode[] {
        radTreeNode1,
        radTreeNode3,
        radTreeNode5,
        radTreeNode7});
        this.radTreeView1.RightToLeft = System.Windows.Forms.RightToLeft.No;
        // 
        // 
        // 
        this.radTreeView1.RootElement.ForeColor = System.Drawing.Color.Black;
        this.radTreeView1.Size = new System.Drawing.Size(284, 337);
        this.radTreeView1.TabIndex = 0;
        this.radTreeView1.Text = "radTreeView1";
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(284, 337);
        this.Controls.Add(this.radTreeView1);
        this.Name = "Form1";
        this.Text = "Form1";
        ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).EndInit();
        this.ResumeLayout(false);
    }
    #endregion
    private Telerik.WinControls.UI.RadTreeView radTreeView1;
}

Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;
using Telerik.WinControls.UI;
  
  
  
    public partial class Form1 : Form
    {
  
        public Form1()
        {
            InitializeComponent();
            this.radTreeView1.MultiSelect = true;
        }
  
        private void radButton1_Click(object sender, EventArgs e)
        {
            this.radTreeView1.SelectedNodes.Clear();
        }
    }

If you find that this doesn't work for you, I'd advise to upgrade to the latest version. Besides the radTreeView there are many other enhancements that I'm sure you will fin of benefit.
Hope that helps
Richard
0
jack abdallah
Top achievements
Rank 1
answered on 11 Apr 2011, 05:06 PM
HI Richard 10x for the reply
Tags
Treeview
Asked by
jack abdallah
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
jack abdallah
Top achievements
Rank 1
Share this question
or