private void SortNodes(TreeListNodeCollection lstNodes, int i) { foreach (TreeListNode treelistNode in lstNodes) { if (treelistNode.Nodes.Count > 0) SortNodes(treelistNode.Nodes, i); } //�����ڵ��������� TreeListNode[] arrayNode = new TreeListNode[lstNodes.Count]; for (int row = 0; row < lstNodes.Count; row++) { arrayNode[row] = lstNodes[row]; } if (i == 0) { Array.Sort(arrayNode, delegate(TreeListNode node1, TreeListNode node2) { if (sortAsc) { //���� if (regNumber.IsMatch(node1.Text) && regNumber.IsMatch(node2.Text)) { return decimal.Parse(node1.Text).CompareTo(decimal.Parse(node2.Text)); } else { return node1.Text.CompareTo(node2.Text); } } else { //���� if (regNumber.IsMatch(node1.Text) && regNumber.IsMatch(node2.Text)) { return decimal.Parse(node2.Text).CompareTo(decimal.Parse(node1.Text)); } else { return node2.Text.CompareTo(node1.Text); } } }); } else //�Ƚϵ�subitems { Array.Sort(arrayNode, delegate(TreeListNode node1, TreeListNode node2) { string text1 = ""; string text2 = ""; if (node1.SubItems.Count > i - 1) { text1 = node1.SubItems[i - 1].Text; } if (node2.SubItems.Count > i - 1) { text2 = node2.SubItems[i - 1].Text; } if (sortAsc) { //���� if (regNumber.IsMatch(text1) && regNumber.IsMatch(text2)) { return decimal.Parse(text1).CompareTo(decimal.Parse(text2)); } else { return text1.CompareTo(text2); } } else { //���� if (regNumber.IsMatch(text1) && regNumber.IsMatch(text2)) { return decimal.Parse(text2).CompareTo(decimal.Parse(text1)); } else { return text2.CompareTo(text1); } } }); //�Զ�������ʽ } //�������Ľڵ�������ӵ������� for (int c = lstNodes.Count - 1; c >= 0; c--) { lstNodes.RemoveAt(c); } for (int c = 0; c < arrayNode.Length; c++) { lstNodes.Add(arrayNode[c]); } }
public TreeListNodeCollection GetAllSelectNodes() { alSelectNodes = new TreeListNodeCollection(); foreach (TreeListNode node in nodes) { if (node.Selected) alSelectNodes.Add(node, false); GetAllSelectNodes(node); } return alSelectNodes; }
private TreeListNodeCollection GetSelectedNodes(TreeListNode node) { TreeListNodeCollection list = new TreeListNodeCollection(); for (int i=0; i<node.Nodes.Count; i++) { // check if current node is selected if (node.Nodes[i].Selected) { list.Add(node.Nodes[i]); } // chech if node is expanded and has // selected children if (node.Nodes[i].IsExpanded) { TreeListNodeCollection list2 = GetSelectedNodes(node.Nodes[i]); for (int j=0; j<list2.Count; j++) { list.Add(list2[i]); } } } return list; }