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);
}
}
}