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

Issue with checked box images during programmatically expanding childern

6 Answers 128 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
John D.
Top achievements
Rank 1
John D. asked on 14 Nov 2011, 07:39 PM

Since upgrading from Q2 2010 (Currently on v.2011.2.11.831), I have found an issue with the checkboxes not drawing properly when you click on the parent check box  which recursively checks all children nodes (see Main 2 –Subs in jpg).  If you expand the node first or after the first time the checkboxes draw properly.  Is there a something I can do to force the redraw so the checkboxes paint correctly?

Below is a sample program and the code I use to recursively check the child nodes. If you click on the checkbox of one of the Mains it will check all children and expand it.

 

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
namespace TreeViewTest
{
    public partial class Form1 : Form
    {
        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);
        }
        private Telerik.WinControls.UI.RadTreeView radTreeView1;
        private void InitializeComponent()
        {
            this.radTreeView1 = new Telerik.WinControls.UI.RadTreeView();
            ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).BeginInit();
            this.SuspendLayout();
            // 
            // radTreeView1
            // 
            this.radTreeView1.Location = new System.Drawing.Point(1, 13);
            this.radTreeView1.Name = "radTreeView1";
            this.radTreeView1.Size = new System.Drawing.Size(496, 347);
            this.radTreeView1.SpacingBetweenNodes = -1;
            this.radTreeView1.TabIndex = 0;
            this.radTreeView1.Text = "radTreeView1";
            this.radTreeView1.NodeCheckedChanged += new Telerik.WinControls.UI.RadTreeView.TreeViewEventHandler(this.radTreeView1_NodeCheckedChanged);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(497, 372);
            this.Controls.Add(this.radTreeView1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).EndInit();
            this.ResumeLayout(false);
  
        }
  
        public Form1()
        {
            InitializeComponent();
        }
  
        private void radTreeView1_NodeCheckedChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
        {
            this.radTreeView1.NodeCheckedChanged -= radTreeView1_NodeCheckedChanged;
            if (e.Node.Nodes.Count > 0)
            {
                this.CheckAllChildNodes(e.Node, e.Node.Checked);
            }
            e.Node.Expanded = true;
            RadTreeNode topNode = GetTopNode(e.Node);
            CheckAllChildNodesForChecked(topNode);
            this.radTreeView1.NodeCheckedChanged += new RadTreeView.TreeViewEventHandler(radTreeView1_NodeCheckedChanged);
  
        }
        private void CheckAllChildNodes(RadTreeNode treeNode, bool nodeChecked)
        {
            foreach (RadTreeNode node in treeNode.Nodes)
            {
                node.Checked = nodeChecked;
                if (node.Nodes.Count > 0)
                {
                    this.CheckAllChildNodes(node, nodeChecked);
                }
            }
        }
        private bool CheckAllChildNodesForChecked(RadTreeNode treeNode)
        {
            bool childChecked = false;
            foreach (RadTreeNode node in treeNode.Nodes)
            {
                if (node.Nodes.Count > 0)
                {
                    if (this.CheckAllChildNodesForChecked(node))
                    {
                        childChecked = true;
                    }
                }
                else
                {
                    if (!childChecked)
                    {
                        childChecked = node.Checked;
                    }
                }
            }
            if (childChecked)
            {
                treeNode.Checked = true;
            }
            else
            {
                treeNode.Checked = false;
            }
  
            return childChecked;
        }
        private RadTreeNode GetTopNode(RadTreeNode treeNode)
        {
            RadTreeNode topTreeNode = treeNode;
            if (topTreeNode.Parent != null)
            {
                topTreeNode = GetTopNode(topTreeNode.Parent);
            }
  
            return topTreeNode;
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
            radTreeView1.Nodes.Clear();
            RadTreeNode root = new RadTreeNode("root");
            root.CheckType = CheckType.CheckBox;
            for (int x = 1; x < 4; x++)
            {
                RadTreeNode main = new RadTreeNode("Main " + x.ToString());
                main.CheckType = CheckType.CheckBox;
                for (int y = 1; y < 4; y++)
                {
                    RadTreeNode sub = new RadTreeNode("Sub " + y.ToString());
                    sub.CheckType = CheckType.CheckBox;
                    main.Nodes.Add(sub);
                }
                main.Expanded = false;
                root.Nodes.Add(main);
            }
            root.Expanded = true;
            radTreeView1.Nodes.Add(root);
        }
  
    }
}

6 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 17 Nov 2011, 05:24 PM
Hello John,

Thank you for writing.

The issue that you are experiencing is already reported by another user of ours, and it is logged in PITS. Here is a link to the item, where you can subscribe for it. We have addressed this case in our latest release (Q3 2011), which you can download from your account. Please download and install this release and test how it works in your case. In my local tests everything works correctly.

I am looking forward to your feedback.

Greetings,
Stefan
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Ryan
Top achievements
Rank 1
answered on 13 Jul 2012, 09:06 PM
This issue is occurring in the 2012 Q1 release, file version 2012.608.20.  Is there a work around, like having the treeView update?



Thanks,
Ryan
0
Stefan
Telerik team
answered on 17 Jul 2012, 11:11 AM
Hello Ryan,

Indeed, this issue appears in our latest version. As a workaround, could you please try calling the EndUpdate method of the TreeViewElement and let me know how it works in your case:
radTreeView1.TreeViewElement.EndUpdate();
 
All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Brennan
Top achievements
Rank 1
answered on 29 Sep 2014, 04:39 PM
In version 2013.3.1016.40 and this is still not fixed. The EndUpdate method proposed by Stefan did not work.  I also tried EditEdit as well as calling both EndEdit and EndUpdate on both the TreeView control itself and the TreeViewElement.


0
Brennan
Top achievements
Rank 1
answered on 29 Sep 2014, 04:45 PM
Okay, just to follow-up what Stefan suggested half works.  You also have to add a BeginUpdate() in there somewhere.  

For example, my TreeView is in a drop down menu where upon opening the drop down, I call "ExpandNodes()" which expands any node in the TreeView that has a "checked" child node.  I added the EndUpdate() call at the end of ExpandNodes() and still had the weird painting issue, however, if I added a BeginUpdate() before my "ExpandNodes()" coupled with the EndUpdate() call at the end.  The issue seemed to be resolved.

Hope this helps someone else.
0
Stefan
Telerik team
answered on 30 Sep 2014, 07:36 AM
Hi Breannan,

This issue seems to be resolved in Q1 2013. I have tested it with both your and the latest version and I am not able to reproduce it. If you experience it with a later version than Q1 2013, may I please ask you to send us a sample allowing us to reproduce it, and we will look into it.

Thank you in advance for your cooperation.

Regards,
Stefan
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Treeview
Asked by
John D.
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Ryan
Top achievements
Rank 1
Brennan
Top achievements
Rank 1
Share this question
or