如何对 UltraTree 中的节点重新排序?

发布于 2024-12-14 15:29:11 字数 903 浏览 3 评论 0原文

我有一个如下所示的类:

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

如何重新排序节点,以便它们以与我在类中的顺序相同的顺序出现?

I've got a class that looks like this:

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; }
}

When I bind the data like this:

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

SetupTree(status);

It puts my parent nodes in a different order:

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

How do I reorder the nodes so they appear in the same order that I have them in my class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柏拉图鍀咏恒 2024-12-21 15:29:11

您必须创建自己的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();

You have to make your own IComparer. Something like this:

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);
        }
    }
}

And then just set SortComparer property of your UltraTree instance:

ultraTree1.SortComparer = new GeneralStatusInfoMemberOrderComparer();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文