Sorting Unbound Datagrid with Numerical Data

Category:
C#, VB.NET, ASP.NET
Type:
Snippets
Difficulty:
Intermediate
Author:
Nathan

Version Compatibility: Visual Basic.NET, ASP.NET

More information:
I didn't find many articles about this, and everyone I found was incomplete or didn't truly sort numerical values. So I decided to write my own and provide it here for others to use. When sorting a column programmatically, if it is determined by the first line to be non-numeric it uses the traditional sort method inherent in the dataGridView. If it is numeric, it compares the numeric values and adjusts the position of the row accordingly. I think it is very strange this ability is not built into the control itself. This works as fast as the original sorting method as far as i can tell. Happy coding.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: