public void Sort(List <int> sortlst) { var slsdfs = (from t in ChildItems where sortlst.Contains(t.NodeId) select t.NodeId).ToList(); var st = (from t in sortlst where slsdfs.Contains(t) select t).Distinct().ToList(); var notex = (from t in ChildItems where st.Contains(t.NodeId) == false select t).ToList(); foreach (var f in notex) { if (ChildItems.Contains(f)) { ChildItems.Remove(f); } } for (int i = 0; i < ChildItems.Count; i++) { if (ChildItems[i].NodeId == st[i]) { continue; } foreach (var l in ChildItems) { if (l.NodeId == st[i]) { var tmp = l; ChildItems.Remove(l); ChildItems.Insert(i, tmp); break; } } } foreach (var f in notex) { ChildItems.Add(f); } }