Completed
Last Updated: 12 Mar 2014 09:48 by ADMIN
ADMIN
Georgi I. Georgiev
Created on: 19 Nov 2013 09:31
Category: TreeView
Type: Bug Report
1
FIX. RadTreeView - when TriState mode is set to true the NodesNeeded event is fired for all levels of hierarchy instead only for the next one
To reproduce: 
Add a RadTreeView to a form and use the following code:
private List<EntityA> entities = new List<EntityA>(); public Form1() { InitializeComponent(); radTreeView1.TriStateMode = true; entities = new List<EntityA>(); for (int i = 0; i < 10; i++) { var newEntityI = new EntityA(i.ToString()); for (int j = 0; j < 100; j++) { var newEntityJ = new EntityB(j.ToString()); for (int k = 0; k < 1000; k++) { var newEntityK = new EntityC(k.ToString()); newEntityJ.Entities.Add(newEntityK); } newEntityI.Entities.Add(newEntityJ); } entities.Add(newEntityI); } } private void checkBox1_CheckedChanged(object sender, EventArgs e) { foreach (var node in radTreeView1.Nodes) { node.Checked = checkBox1.Checked; } } private void radTreeView1_NodesNeeded(object sender, NodesNeededEventArgs e) { if (e.Parent == null) { foreach (var entity in entities) { e.Nodes.Add(new RadTreeNode(entity.Name, false) { CheckState = ToggleState.Off, Tag = entity }); } } else if (e.Parent.Tag is EntityA) { var currentEntity = e.Parent.Tag as EntityA; foreach (var entity in currentEntity.Entities) { e.Nodes.Add(new RadTreeNode(entity.Name, false) { CheckState = e.Parent.CheckState, Tag = entity }); } } else if (e.Parent.Tag is EntityB) { var currentEntity = e.Parent.Tag as EntityB; foreach (var entity in currentEntity.Entities) { e.Nodes.Add(new RadTreeNode(entity.Name, false) { CheckState = e.Parent.CheckState, Tag = entity }); } } else if (e.Parent.Tag is EntityC) { } } 
Put a breakpoint in the last If statement, you will notice that the breakpoint is being hit, while it is not if the TrieStateMode is set to false 

Workaround: 
Use the following custom RadTreeNode: 
public class MyTreeNode : RadTreeNode { private FieldInfo triStateField; public MyTreeNode() : base() { } public MyTreeNode(string text) : base(text) { } public MyTreeNode(string text, RadTreeNode[] children) : base(text, children) { } public MyTreeNode(string text, bool expanded) : base(text, expanded) { } public MyTreeNode(string text, Image image) : base(text, image) { } public MyTreeNode(string text, Image image, bool expanded) : base(text, image, expanded) { } public override ToggleState CheckState { get { return base.CheckState; } set { bool set = false; if (this.TreeViewElement != null && this.TreeViewElement.TriStateMode) { if (this.triStateField == null) { this.triStateField = typeof(RadTreeViewElement).GetField("triStateMode", BindingFlags.Instance | BindingFlags.NonPublic); } triStateField.SetValue(this.TreeViewElement, false); set = true; } base.CheckState = value; if (set) { this.triStateField.SetValue(this.TreeViewElement, true); } } } }

1 comment
ADMIN
Ralitsa
Posted on: 12 Mar 2014 09:47
Resolution: 
The described scenario is not an issue. When the RadTreeView is in TriStateMode and user click on RadCheckBox element in RadTreeNode, RadTreeView should iterate through all RadTreeNodes in all levels to calculate the correct state of the RadCheckBox. This is the reason for described behavior. 
To use TriStateMode together with Load on Demand is not good practice, because the idea of load on demand is to create nodes when they should display while TriStateMode requires to know for whole nodes hierarchy.