Как отсортировать список по нескольким значениям
Привет Ребята
В настоящее время у меня есть проблема, пытающаяся отсортировать список, проблема, с которой я сталкиваюсь, заключается в том, что я пытался отсортировать по атрибутам, но безуспешно
Мне нужно сделать сортировку по 3 различным атрибутам
Сортировать по
Attribute1
затем
Attribute2
затем
Attribute3
но не имея никакого везения
Что я уже пробовал:
public class CustomComparer : System.Collections.IComparer { public int Compare(object x, object y) { RadListBoxItem p1 = new RadListBoxItem(); RadListBoxItem p2 = new RadListBoxItem(); if (x is RadListBoxItem) p1 = x as RadListBoxItem; else throw new ArgumentException("Object is not of type RadListBoxItem."); if (y is RadListBoxItem) p2 = y as RadListBoxItem; else throw new ArgumentException("Object is not of type RadListBoxItem."); int cmp = 0; if (p1.ListBox.Sort == RadListBoxSort.Ascending) { //here we compare the Values of the items if (String.Compare(p1.Value, p2.Value, !p1.ListBox.SortCaseSensitive) == 0) { return 0; } if (String.Compare(p1.Attributes["Attribute1"], p2.Attributes["AgentHierachy"], !p1.ListBox.SortCaseSensitive) == 0) { return 0; } if (String.Compare(p1.Attributes["Attribute2"], p2.Attributes["SubAgentID"], !p1.ListBox.SortCaseSensitive)==0) { return 0; } } if (p1.ListBox.Sort == RadListBoxSort.Descending) { //here we compare the Values of the items cmp = String.Compare(p1.Value, p2.Value, !p1.ListBox.SortCaseSensitive) * -1; } return cmp; }
Maciej Los
Извините, но вы пытаетесь сортировать элементы списка вместо данных?