HI all,
I have develop a windows application using VB.net2.0, in that I have a UltraTree control to display the details in 3 level (Master,child and GrandChild) with checkbox.
when i click the master tree checkbox then automatically all child and GrandChild checkbox are marked and vice versa.If any one child or grandchild as unmarked means then the corresponding parent are unmard. which event i call, i need you socution with coding.
Advance thanks for your reply
Hey Ulf Akerstad
Thanks for posting up a great sollution and sharing it with us fellow devs !
Thanks this saved me many headaches
Here is the the same in C#.
public partial class Form1 : Form { bool updatingLock = false; public Form1() { InitializeComponent(); //UIElementDrawParams.CheckBoxGlyphInfo = UIElementDrawParams.Office2007CheckBoxGlyphInfo; } private void uTreeSample_BeforeCheck(object sender, BeforeCheckEventArgs e) { UltraTreeNode treeNode = e.TreeNode; // Do not allow Indeterminate state for leaves. if (IsLeafNode(treeNode)) treeNode.Override.NodeStyle = NodeStyle.CheckBox; } private void CreateExampleTree() { int i = 0; int j = 0; int k = 0; for (i = 1; i <= 5; i++) { UltraTreeNode rootNode = this.uTreeSample.Nodes.Add("Node " + i.ToString()); for (j = 1; j <= 5; j++) { UltraTreeNode childNode = default(UltraTreeNode); childNode = rootNode.Nodes.Add(rootNode.Key + " Child " + j.ToString()); for (k = 1; k <= 5; k++) { UltraTreeNode childchildNode = default(UltraTreeNode); childchildNode = childNode.Nodes.Add(childNode.Key + " Child " + k.ToString()); } } } } private void uTreeSample_AfterCheck(object sender, Infragistics.Win.UltraWinTree.NodeEventArgs e) { if (updatingLock) return; //Because the Check change was caused programatically in HandleTreeCheckedStateChanges(...) UltraTreeNode treeNode = e.TreeNode; updatingLock = true; //Begin handling checked state changes of the tree HandleTreeCheckedStateChanges(treeNode); //End handling checked state changes of the tree updatingLock = false; } private void HandleTreeCheckedStateChanges(UltraTreeNode treeNode) { // Each time a non-leaf node's CheckState changes // 1) Make sure it is Checked or Unchecked - we should not be able to make it indeterminate by clicking! if (treeNode.CheckedState == CheckState.Indeterminate) treeNode.CheckedState = CheckState.Unchecked; // Since NodeStates: Unchecked => Checked => Indeterminate // 2) Set all child nodes to same state. SetChildNodesCheckStatesToSameAs(treeNode); UpdateParentNodeCheckState(treeNode); } private void SetChildNodesCheckStatesToSameAs(UltraTreeNode treeNode) { if (IsLeafNode(treeNode)) return; //End recursion foreach (UltraTreeNode childNode in treeNode.Nodes) { childNode.CheckedState = treeNode.CheckedState; SetChildNodesCheckStatesToSameAs(childNode); } } private void UpdateParentNodeCheckState(UltraTreeNode treeNode) { UltraTreeNode parentNode = treeNode.Parent; if (parentNode == null) return; //End recursion // Get the nodes collection to which the specified childNode belongs TreeNodesCollection nodesCollection = treeNode.ParentNodesCollection; // count of the number of checked nodes int checkedNodesCount = 0; int indeterminateCount = 0; foreach (UltraTreeNode node in nodesCollection) { if (node.CheckedState == CheckState.Checked) checkedNodesCount += 1; if (node.CheckedState == CheckState.Indeterminate) indeterminateCount += 1; } // Set appropriate CheckState of the parentNode if (checkedNodesCount == nodesCollection.Count) { parentNode.CheckedState = CheckState.Checked; } else if (checkedNodesCount == 0 && indeterminateCount == 0) { parentNode.CheckedState = CheckState.Unchecked; } else { parentNode.CheckedState = CheckState.Indeterminate; } // Traverse up the tree... UpdateParentNodeCheckState(parentNode); } private bool IsLeafNode(UltraTreeNode treeNode) { return treeNode.Nodes.Count == 0; } private void Form1_Load(object sender, EventArgs e) { CreateExampleTree(); } private void ultraButton1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.ShowDialog(); }
This is a very poor article and should be replaced with the code on this page.
Fabulous! Great code.
This should be part of the standard functionality of the UltraTree.