I need to find out how to sort some data by pre-defined pattern.
Lets say I have some strings, which represents product informafion, e. g.
Product1, red, 70/n
Product6, blue, 90/n
Product3, red, 50/n
Product9, white, 33/n
I separated these strings by coma string split and stored them at different Arrays (name, color, price) and then DataTable with same columns.
I can order created rows by color using :
DataView.sort = "color"
or by LINQ with
DataRow[] dr = table.Select().OrderBy(u=>u[color]).ToArray();
DataTable sortedtable = dr.CopyToDataTable();
However this is just simple sorting, asc/desc, based on alphabet.
I would like to achieve sorting with pre-defined pattern. In example the item order would be defined by colors in order red, black, blue, white.
Is there anything simple I could do? I think this is possible with checking each row color and comparing it with predefined color list, then building new Array / DataTable based on this order. However I feel that this is weak approach.