I have a DataGridView with 6 columns.
Example:
column1 column2 column3 column4 column5 column6
J6 RES-0112G 123.123 456.456 180 1111
FID2 FIDUCIAL 5.123 -50.005 90 FIDUCIAL
R100 RES-0113G 1.1 -123.123 90 1111
C12 CAP-1234H -99.99 -987.123 45 2222
Q1 CAP-1234Z -99.99 -987.123 45 4444
J3 RES-0112G 123.123 999.999 0 1111
FID1 FIDUCIAL 23.123 23.123 0 FIDUCIAL
F1 CAP-1234 -88.99 -555.111 45 DDDD
C11 CAP-1234Z -123.99 -123.123 270 abc2222
And I would like to sort it in a special order. Let’s say I want to sort it by the last value (column 6) in this sequence:
FIDUCIAL, 1111, 2222, DDDD, 4444
AND then sort it secondly by the 2nd column alpha-numerically. (NOTE THE abc2222 sorts by “2222” not “abc”).
So the updated DataGridView would look like this: (For the FIDUCIALS I would like to sort by column 1 instead of column 2)
column1 column2 column3 column4 column5 column6
FID1 FIDUCIAL 23.123 23.123 0 FIDUCIAL
FID2 FIDUCIAL 5.123 -50.005 90 FIDUCIAL
J6 RES-0112G 123.123 456.456 180 1111
J3 RES-0112G 123.123 999.999 0 1111
R100 RES-0113G 1.1 -123.123 90 1111
C11 CAP-1234C -123.99 -123.123 270 abc2222
C12 CAP-1234H -99.99 -987.123 45 2222
F1 CAP-1234 -88.99 -555.111 45 DDDD
Q1 CAP-1234Z -99.99 -987.123 45 4444
Does anyone know how to properly sort this? I am using a SortableBindingList<>
I’ve created a sample code to show you the technique itself. I hope you will not find it complicated to adapt to your needs. The basic idea is that you group by required column and then apply custom sort inside the group. I didn’t grasp the sorting algorithm for column6, so I’ve made a simple sorting based on your sample data. Hope it helps!