troubleshooting Question

Sorting a databound DataGridView Column numerically?

Avatar of JasonWilliam
JasonWilliam asked on
.NET ProgrammingVisual Basic.NET
7 Comments1 Solution1467 ViewsLast Modified:
I have to believe this is something really easy I'm just overlooking...

I've got a DataGridView that is bound to a datasource.  The datasource's column has had its values populated as integers.  But, when I sort on this column, I end up with a sort as if the data was of type string.  For example:

#
1
2
3
10
11

Sorts to
#
1
10
11
2
3

When it obviously should sort numerically.  I've tried handling the CellFormatting event too:
    Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
            If Not IsNumeric(e.Value) Then Return
            e.Value = CType(e.Value, Integer)
End Sub

But I end up with the same results.  What the heck am I missing???
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros