Overcoming a .NET Sorting Limitation on an Epicor Project
Updated September 14, 2016
We were developing a cycle count application for one of our customers who required that their bins be sorted into alpha-numeric order: 14B, 21G, 21L, A7B, A9A, B5A, D4E1, E16A2, E16B2, etc. In the past, they had written their own sorting algorithm for a Crystal Report and so the cycle count applications dashboard that was replacing the report would also need items sorted into these bins. The issue we had to overcome is that .NET does not have a built-in sorting algorithm for an alpha-numeric values. There are basic algorithms which can handle the sorting of a list of numbers or a list of strings. In our case however, we needed to account for both letters and numbers, with a list of varying degrees of length in each of its items.
To accomplish this, we wrote a custom class that inherited the IComparer Interface, exposing the Compare method used to compare two values to see which one is greater. The custom class can take any type of object as input; a string, an integer, DataRow, etc. In our case, we got our output DataTable and parsed this into an ArrayList. We apply the sorting to the ArrayList, implementing a new instance of our sorting class, and then parsed the sorted array back into a DataTable for display in a DataGridView.