private void SortBy(string arg) { arg = arg.ToLower(); List <Auction> temp = SearchedList.ToList <Auction>(); if (arg.ToLower() == "name") { if (sorted[arg]) { temp.Reverse(); sorted[arg] = false; } else { temp.Sort(delegate(Auction a1, Auction a2) { return(a1.Name.CompareTo(a2.Name)); }); sorted[arg] = true; } } if (arg.ToLower() == "time left") { if (sorted[arg]) { temp.Reverse(); sorted[arg] = false; } else { temp.Sort(delegate(Auction a1, Auction a2) { return(a1.TimeLeftIndex.CompareTo(a2.TimeLeftIndex)); }); sorted[arg] = true; } } if (arg.ToLower() == "bid") { if (sorted[arg]) { temp.Reverse(); sorted[arg] = false; } else { temp.Sort(delegate(Auction a1, Auction a2) { return(a1.Bid.CompareTo(a2.Bid)); }); sorted[arg] = true; } } if (arg.ToLower() == "buyout") { if (sorted[arg]) { temp.Reverse(); sorted[arg] = false; } else { temp.Sort(delegate(Auction a1, Auction a2) { return(a1.Buyout.CompareTo(a2.Buyout)); }); sorted[arg] = true; } } if (arg.ToLower() == "seller") { if (sorted[arg]) { temp.Reverse(); sorted[arg] = false; } else { temp.Sort(delegate(Auction a1, Auction a2) { return(a1.SellerName.CompareTo(a2.SellerName)); }); sorted[arg] = true; } } if (arg.ToLower() == "amount") { if (sorted[arg]) { temp.Reverse(); sorted[arg] = false; } else { temp.Sort(delegate(Auction a1, Auction a2) { return(a1.Amount.CompareTo(a2.Amount)); }); sorted[arg] = true; } } FixDic(arg); SearchedList.Clear(); foreach (Auction a in temp) { SearchedList.Add(a); } }