1
请让我知道,如果我可以根据下面的情况下实现RadTreeNode再根据当时USERLOGIN顺序按字母顺序排序
因此,如果用户登录的域/ dan.campbell然后我需要在RadTreeView排序为以下:
CAMPBELL,DAN
- 耐克
- 彪马
ANSTON,ERIC
- 阿迪达斯
- 彪马
BRIAN,ERIC
- 阿迪达斯
- 彪马
基于下面的C赋,当前树被示出,如以下:
ANSTON,ERIC
- 阿迪达斯
- 彪马
BRIAN,ERIC
- 阿迪达斯
- 彪马
CAMPBELL,DAN
- 耐克
彪马
保护无效的Page_Load(对象发件人,EventArgs的) { BuildTree(); SortClass(); }
//Sort all RadTreeNode in Ascending public void SortClass() { SortNodes(treProduct.Nodes); }
公共无效BuildTree() { EntityCollection集合= GetProduct(); treProduct.Nodes.Clear();
ArrayList pgnodes = new ArrayList(); RadTreeNode pnode = null; RadTreeNode snode = null; foreach (ProductEntity p in collection) { pnode = null; foreach(RadTreeNode n in pgnodes) { if(n.Text.Trim() == p.LastName.Trim().ToUpper() + "," +" " + p.FirstName.Trim().ToUpper()) { pnode = n; break; } } if(pnode != null) { RadTreeNode productNode = new RadTreeNode(p.ProductName.toString()); pnode.nodes.Add(productNode); } else { RadTreeNode userNode = new RadTreeNode(p.LastName.Trim().ToUpper() + "," +" " + p.FirstName.Trim().ToUpper()); RadTreeNode productNode = new RadTreeNode(p.ProductName.toString()); userNode.Nodes.Add(productNode); pgnodes.Add(userNode); } } foreach(RadTreeNode pg in pgnodes) { treProduct.Nodes.Add(pg); } treProduct.CollapseAllNode(); } /// <summary> /// The sort node is called for each node level sorting the child node /// </summary> /// <param name="collection"></param> public void Sort(RadTreeNodeCollection collection) { RadTreeNode[] nodes = new RadTreeNode[collection.Count]; collection.CopyTo(nodes, 0); Array.Sort(nodes, new NodeSorter()); collection.Clear(); collection.AddRange(nodes); } /// <summary> /// SortNodes is a recursive method enumarating and sorting all area /// </summary> /// <param name="collection"></param> private void SortNodes(RadTreeNodeCollection collection) { Sort(collection); foreach (RadTreeNode node in collection) { if (node.Nodes.Count > 0) { SortNodes(node.Nodes); } } } /// <summary> /// TreeNodeCOmpare define the sorting criteria /// </summary> public class NodeSorter : IComparer { public int Compare(object x, object y) { RadTreeNode tx = (RadTreeNode)x; RadTreeNode ty = (RadTreeNode)y; //if (tx.Text.Length != ty.Text.Length) // return tx.Text.Length - ty.Text.Length; return string.Compare(tx.Text, ty.Text); } }