Reputation: 863
m_ListOfsAllFields.OrderBy(Function(x) x.DisplayOrder)
here I have DisplayOrder = 0 for 2 fields, so orderby is messing up and not ordering properly. How can I use orderby to order this collection?
Upvotes: 1
Views: 694
Reputation: 126932
If two objects can have the same value for a property used in one OrderBy
and you want to further differentiate, add a ThenBy
.
Dim results = sequence.OrderBy(yourFunction).ThenBy(anotherFunction)
Upvotes: 2
Reputation: 755209
The problem here is that OrderBy
doesn't modify the collection in place but instead creates a new IEnumerable(Of T)
instance which is correctly ordered. You need to save the result int the m_listOfsAllFields
value.
m_ListOfsAllFields = m_ListOfsAllFields.OrderBy(Function(x) x.DisplayOrder)
If this is an instance of List(Of T)
though you should just use the Sort
method directly.
m_ListOfsAllFields.Sort(Function (l, r) l.DisplayOrder.CompareTo(r.DisplayOrder))
Upvotes: 5