Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
QuestionTextbox help! Pin
Kurac121-Nov-12 11:18
Kurac121-Nov-12 11:18 
AnswerRe: Textbox help! Pin
Mycroft Holmes21-Nov-12 12:01
professionalMycroft Holmes21-Nov-12 12:01 
QuestionSpecialized List Sorting question Pin
NuclearMan8521-Nov-12 7:12
NuclearMan8521-Nov-12 7:12 
AnswerRe: Specialized List Sorting question Pin
Richard Deeming21-Nov-12 8:03
mveRichard Deeming21-Nov-12 8:03 
AnswerRe: Specialized List Sorting question Pin
SledgeHammer0121-Nov-12 8:06
SledgeHammer0121-Nov-12 8:06 
AnswerRe: Specialized List Sorting question Pin
Richard Deeming21-Nov-12 8:32
mveRichard Deeming21-Nov-12 8:32 
AnswerRe: Specialized List Sorting question Pin
PIEBALDconsult21-Nov-12 8:57
mvePIEBALDconsult21-Nov-12 8:57 
AnswerRe: Specialized List Sorting question Pin
BobJanova21-Nov-12 22:50
BobJanova21-Nov-12 22:50 
Make a wrapper class that you can use to preserve the order:

class OrderHelper<T> : IComparable<OrderHelper<T>> {
 public T Item {get; private set;}
 public int Order {get; private set;}

 public OrderHelper(T item, int order) { this.Item = item; this.Order = order; }

 public int CompareTo(OrderHelper<T> other) {
  return Comparer<T>.Default.Compare(Item, other.Item);
 }
}


Create a list of these from your primary sort list:
int index = 0;
List<OrderHelper<int>> orderedList = listOne.Select(i => new OrderHelper(i, index++)).ToList();


Sort that list, and then you can retrieve the index list:
orderedList.Sort();
List<int> indices = orderedList.Select(oi => oi.Order).ToList();


Finally you can order the other lists by that index set:
public static List<T> OrderBy(List<T> list, List<int> indices){
 List<T> r = new List<T>(indices.Count);
 for(int i = 0; i < r.Count; i++){
  r[i] = list[indices[i]];
 }  
 return r;
}

// ...
listTwo = OrderBy(listTwo, indicies);
listThree = OrderBy(listThree, indicies);
// etc

QuestionWinForms Class Design Pin
Member 961929521-Nov-12 6:43
Member 961929521-Nov-12 6:43 
AnswerRe: WinForms Class Design Pin
Richard MacCutchan21-Nov-12 7:15
mveRichard MacCutchan21-Nov-12 7:15 
GeneralRe: WinForms Class Design Pin
Matt U.21-Nov-12 8:16
Matt U.21-Nov-12 8:16 
GeneralRe: WinForms Class Design Pin
Richard MacCutchan21-Nov-12 8:56
mveRichard MacCutchan21-Nov-12 8:56 
GeneralRe: WinForms Class Design Pin
Matt U.21-Nov-12 8:59
Matt U.21-Nov-12 8:59 
GeneralRe: WinForms Class Design Pin
Richard MacCutchan21-Nov-12 9:06
mveRichard MacCutchan21-Nov-12 9:06 
GeneralRe: WinForms Class Design Pin
Matt U.21-Nov-12 9:21
Matt U.21-Nov-12 9:21 
GeneralRe: WinForms Class Design Pin
PIEBALDconsult21-Nov-12 10:27
mvePIEBALDconsult21-Nov-12 10:27 
AnswerRe: WinForms Class Design Pin
PIEBALDconsult21-Nov-12 9:07
mvePIEBALDconsult21-Nov-12 9:07 
QuestionUplaod Article To Codeproject Pin
katlegoEmmnanuelNkosi21-Nov-12 3:44
katlegoEmmnanuelNkosi21-Nov-12 3:44 
AnswerRe: Uplaod Article To Codeproject Pin
PIEBALDconsult21-Nov-12 3:48
mvePIEBALDconsult21-Nov-12 3:48 
AnswerRe: Uplaod Article To Codeproject Pin
Richard MacCutchan21-Nov-12 4:34
mveRichard MacCutchan21-Nov-12 4:34 
QuestionPrint Crystal Report in c# Using Access Database? Pin
kashifjaat21-Nov-12 2:09
kashifjaat21-Nov-12 2:09 
QuestionGenerate Morse Code Sound Pin
long dao21-Nov-12 1:24
long dao21-Nov-12 1:24 
AnswerRe: Generate Morse Code Sound Pin
Pete O'Hanlon21-Nov-12 1:45
mvePete O'Hanlon21-Nov-12 1:45 
GeneralRe: Generate Morse Code Sound Pin
long dao21-Nov-12 1:54
long dao21-Nov-12 1:54 
GeneralRe: Generate Morse Code Sound Pin
Pete O'Hanlon21-Nov-12 2:05
mvePete O'Hanlon21-Nov-12 2:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.