Results 1 to 4 of 4

Thread: [RESOLVED] VB.Net 2008 Sort DataGridViewTextBoxColumn Numeric values

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Resolved [RESOLVED] VB.Net 2008 Sort DataGridViewTextBoxColumn Numeric values

    I’m using VB.Net 2008 application program.

    I’m using DataGridView, where column types DataGridViewTextBoxColumn. I have 3 fields. 1 field values are numeric, 1 field values are string and 1 field values are decimal.

    When I try to sort the string value column, it sorts correctly. But when i try to sort the numeric value column, it sorts as if its string value.

    I searched a lot to make it sort numerically. But I couldn’t find it.

    If you know how i can sort that column, please help me. If you can provide an example, that will be so helpful.

    Thanks in advance.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    25

    Re: VB.Net 2008 Sort DataGridViewTextBoxColumn Numeric values

    Have you defined the column as int32?

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: VB.Net 2008 Sort DataGridViewTextBoxColumn Numeric values

    i tried to recreate your problem...
    as Skilleddreamer said, you must be adding the numeric (integer?) values as strings.

    here's the code i used to add some rows to my dgv, which sorts correctly:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim strings() As String = {"one", "two", "three", "four", "five"}
    5.         For x As Integer = 1 To 50
    6.             DataGridView1.Rows.Add(x, strings((x - 1) Mod 5), CDec(x + 0.5))
    7.         Next
    8.     End Sub
    9.  
    10. End Class

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Re: VB.Net 2008 Sort DataGridViewTextBoxColumn Numeric values

    Thanks Skilleddreamer and Paul for your help. it's working.

    As you mentioned while adding data to column, somehow i converted that to string. once i removed that, it's working fine and start sorting.

    Thanks a lot for your help...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width