/// <summary> /// Search for the node containing the specified string. /// </summary> /// <param name="value">search string.</param> /// <param name="columnIndex">Node column index.</param> /// <returns>Node is found.</returns> public bool Search(string value, int columnIndex = 0) { _goal = null; if (DFS) { DfsSearch(_tree.Nodes, value, columnIndex); } else { BfsSearch(_tree.Nodes, value, columnIndex); } _tree.CollapseAll(); if (_goal != null) { var parentColl = _goal.ParentCollection; while (parentColl.Parent != null) { parentColl.Parent.Expand(); parentColl = parentColl.Parent.ParentCollection; } _goal.Selected = true; } return(_goal != null); }
// update the sum for category node (first node level) private void RecalcCategory(C1TreeNode node) { if (node.Level == 0) { node.SetValue(null, c_totalPriceIdx); } }
private void GenerateChildNodes(C1TreeNode parentNode) { if (!parentNode.HasChildren && nudLevelsCount.Value > parentNode.Level) { for (var i = 0; i < nudNodesCount.Value; i++) { var node = new C1TreeNode(string.Format("Node {0}.{1}.{2}", parentNode.Level + 1, parentNode.ParentCollection.IndexOf(parentNode), i)); parentNode.Nodes.Add(node); } } }
void LoadProjectStructure() { Assembly asm = Assembly.GetExecutingAssembly(); Stream s = asm.GetManifestResourceStream("ControlExplorer.SourceCode.zip"); C1ZipFile z = new C1ZipFile(); z.Open(s); C1TreeNodeCollection targetNodeCollection = null; int previousLevel = -1; for (int i = 0; i < z.Entries.Count; i++) { string[] partsOfPath = z.Entries[i].FileName.Split('/'); int level = partsOfPath.Length - 2; int imageIndex = 0; if (!string.IsNullOrEmpty(partsOfPath[partsOfPath.Length - 1])) { level = partsOfPath.Length - 1; imageIndex = 2; } string nodeName = partsOfPath[level]; if (targetNodeCollection == null) { targetNodeCollection = c1TreeView1.Nodes; } else { if (previousLevel > level) { targetNodeCollection = targetNodeCollection.Parent.ParentCollection; } else if (previousLevel < level) { targetNodeCollection = targetNodeCollection.Last().Nodes; } } C1TreeNode node = targetNodeCollection.Add(nodeName); node.Images.Add(imageIndex); previousLevel = level; } z.Close(); }
private void DfsSearch(C1TreeNodeCollection nodes, string value, int columnIndex) { foreach (var node in nodes) { if (_goal != null) { return; } if (IsEquals(node.GetValue(columnIndex).ToString(), value)) { _goal = node; return; } DfsSearch(node.Nodes, value, columnIndex); } }
private void BfsSearch(C1TreeNodeCollection nodes, string value, int columnIndex) { var queue = new Queue <C1TreeNode>(nodes); while (queue.Count > 0) { var node = queue.Dequeue(); if (IsEquals(node.GetValue(columnIndex).ToString(), value)) { _goal = node; return; } foreach (var child in node.Nodes) { queue.Enqueue(child); } } }
private void GenerateTreeView() { c1TreeView1.Columns.Clear(); c1TreeView1.Nodes.Clear(); for (var i = 0; i < nudColumnsCount.Value; i++) { var column = new C1TreeColumn(); column.HeaderText = string.Format("Column {0}", i); column.AutoWidth = false; column.Width = 200; c1TreeView1.Columns.Add(column); } for (var i = 0; i < nudRootNodesCount.Value; i++) { var node = new C1TreeNode(string.Format("Node 0.{0}", i)); c1TreeView1.Nodes.Add(node); GenerateChildNodes(node); node.Collapse(true); } }