【问题标题】:How do I reorder nodes in an UltraTree?如何重新排序 UltraTree 中的节点?
【发布时间】:2011-12-25 10:28:53
【问题描述】:

我有一个看起来像这样的类:

public class GeneralStatusInfo
{        
    public List<string> List_BLNumber { get; set; }
    public List<POInfo> List_PONumbers { get; set; }
    public List<string> List_Pickup { get; set; }
    public List<string> List_Origin { get; set; }
    public List<string> List_Destination { get; set; }
    public List<string> List_NotifyName { get; set; }
    public List<AppmntInformation> List_Appointments { get; set; }
}

当我像这样绑定数据时:

List<GeneralStatusInfo> statusBind = new List<GeneralStatusInfo>();
statusBind.Add(status);
utGeneralStatusInfo.DataSource = statusBind;

SetupTree(status);

它将我的父节点以不同的顺序排列:

 Appointment 
 P/O Number 
 B/L Number 
 Origin 
 Pickup 
 Notify 
 Payment
 Destination

如何对节点重新排序,以便它们以与我在课堂上的顺序相同的顺序出现?

【问题讨论】:

    标签: .net infragistics ultratree


    【解决方案1】:

    你必须自己制作IComparer。像这样的:

    public class  GeneralStatusInfoMemberOrderComparer: IComparer
    {
        public  GeneralStatusInfoMemberOrderComparer()
        {
            memberOrdermemberOrder.Add("B/L Number",0);
            memberOrdermemberOrder.Add("P/O Number",1);
            /// 
            /// add more items
            ///
        }
    
        private bool sortAlphabetically=false;
        private Dictionary<string,int> memberOrder  = new Dictionary<string,int>();
    
        public bool SortAlphabetically
        {
            get{return sortAlphabetically;}
            set{sortAlphabetically = value;}
        }
    
        int IComparer.Compare(object x, object y)
        {
            string propertyX = x as string;
            string propertyY = y as string;
    
            if (sortAlphabetically)
            {
                return propertyX.CompareTo(propertyY);
            }
            else
            {
                int orderX= memberOrder.ContainsKey(propertyX) ? memberOrder[propertyX] : -1;
                int orderY= memberOrder.ContainsKey(propertyY) ? memberOrder[propertyY] : -1;
                return orderX.CompareTo(orderY);
            }
        }
    }
    

    然后只需设置 UltraTree 实例的 SortComparer 属性:

    ultraTree1.SortComparer = new GeneralStatusInfoMemberOrderComparer();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-26
      • 2017-03-14
      • 1970-01-01
      • 2021-05-15
      • 2011-03-12
      • 1970-01-01
      • 2023-02-03
      • 1970-01-01
      相关资源
      最近更新 更多