I hope everyone is doing well.
I have a table as shown below:
My requirement is to order the table on the basis of ID and Relationship in such a way that SELF always shows up first, followed by SPOUSE, but SPOUSE may or may not always be present.
Is there a way to order Relationship by Text, instead of using its length? SON has three characters, so it will show up on first if I order by length, also there is the issue of SPOUSE not showing up in few instances.
Help would be most appreciated, thanks in advance!
Can you try the following?
First, set sorted relationship items as the following image, to string array ( let’s say keywords.)
Then use the following expression.
dt = dt.AsEnumerable.OrderBy(Function(r) Int32.Parse(r("ID").ToString)).ThenByDescending(Function(r) Array.IndexOf(keywords,r("Relationship").ToString)).CopyToDataTable
If you want to also sort except SELF and SPOUSE, please add items (such as SON) at the beginning of the array.
I wasn’t aware of Array.Index, thank you for share your hard earned knowledge with the rest of us @Yoichi-san!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.