Saturday, January 5, 2013

how to sort one observable collection with another observable collection in silverlight

how to sort one observable collection with another observable collection in silverlight

i have one string observable collection called "A" contains some values .another string observable collection called "B" contains some value . "A" have 13 value and "B" have 5 value."A" contains "B" values but in different order .i want "B" value in "A" get first priority in combobox.so wht i hve to do ..write some linq query.pls give some ideas

Answers & Comments...

Answer: 1

I dont have my IDE handy but something like this should do it.

This one assumes the same instances exist in the two collections.

var sortedA = observableA.OrderBy(item=>observableB.Contains(item) ? 0 : 1); 

If they are not the same instances and you wanted to compare a property such as name you could also do.

var sortedA = observableA.OrderBy(item=>observableB.Any(item2 => item2.Name == item.Name) ? 0 : 1); 
by : Richard Friendhttp://stackoverflow.com/users/162137

Answer: 2
var a = "1,2,3,4,5,6,7,8,9,10,11,12,13".Split(',').ToList(); var b = "7,8,9,10,11".Split(',').ToList();  var c = a.OrderByDescending(x => b.IndexOf(x)); 
by : deerchaohttp://stackoverflow.com/users/119561




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog