2011-11-09 2 views
1

I는 다음과 같습니다 클래스를 가지고 :UltraTree에서 노드를 어떻게 재정렬합니까?

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 

노드를 다시 정렬하여 클래스에 동일한 순서로 나타낼 수 있습니까?

답변

1

자신을 만들어야합니다. IComparer. 이런 식으로 뭔가 :

ultraTree1.SortComparer = new GeneralStatusInfoMemberOrderComparer(); 
: 다음

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 속성을 설정

관련 문제