Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
P

pekatete

@pekatete
About
Posts
1
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Sorting date column in datagridview
    P pekatete

    Hi - if you are still searching for an answer, I got one for you. It involves implementing the icomparer class. Add this to the your form:

    Public Class DataGridViewSortRowsByDateTime
        Implements System.Collections.IComparer
        Private Direction As Integer = 1
        Public Sub New(ByVal so As SortOrder)
            If so = SortOrder.Descending Then
                Direction = -1
            ElseIf so = SortOrder.Ascending Then
                Direction = 1
            End If
        End Sub
        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer \_
        Implements System.Collections.IComparer.Compare
            Dim RowOne As DataGridViewRow = CType(x, DataGridViewRow)
            Dim RowTwo As DataGridViewRow = CType(y, DataGridViewRow)
            Dim Result As Integer = \_
            System.DateTime.Compare(RowOne.Cells(0).Value, RowTwo.Cells(0).Value)
            Return Result \* Direction
        End Function
    End Class
    

    NOTE: This sorts on column index(0). You can assign your column index to whatever you like by changing the value of x in the statement:

    System.DateTime.Compare(RowOne.Cells(x).Value, RowTwo.Cells(x).Value)

    Then after loading your data into the datagridview, add this line at the end:

    DataGridView1.Sort(New DataGridViewSortRowsByDateTime(SortOrder.Ascending))

    for ascending or:

    DataGridView1.Sort(New DataGridViewSortRowsByDateTime(SortOrder.Descending))

    I hope that helps (it did for me!)

    modified on Friday, November 20, 2009 3:50 AM

    Visual Basic tutorial csharp algorithms help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups