Private Sub Form_Load()
    Dim i As Integer
    
    ListView1.View = lvwReport
    ListView1.ColumnHeaders.Add
    
    For i = 1 To 100
        ListView1.ListItems.Add , , i
    Next i
End SubPrivate Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    Dim i As Integer
    
    For i = 1 To 100
        ListView1.ListItems(i).Text = Format(Val(ListView1.ListItems(i).Text), "000")
    Next i
    
    If ListView1.SortOrder = 0 Then
        ListView1.SortOrder = 1
    Else
        ListView1.SortOrder = 0
    End If
    
    ListView1.SortKey = 0
    ListView1.Sorted = True
    
    For i = 1 To 100
        ListView1.ListItems(i).Text = Val(ListView1.ListItems(i).Text)
    Next i
End Sub

解决方案 »

  1.   

    To: junwhj(junwhj.51.net) 
    你的方法应该是可行的,但我的ListView 中可能有几千条纪录,
    这样的话,会不会速度很慢。
      

  2.   

    使用API可以实现LISTVIEW中数值、日期的排序。Option ExplicitPrivate Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
    Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Type POINT
       X As Long
       Y As Long
    End TypePrivate Type RECT
       Left As Long
       Top As Long
       Right As Long
       Bottom As Long
    End TypePrivate Const LVM_FIRST As Long = &H1000
    Private Const LVM_GETITEM As Long = LVM_FIRST + 5
    Private Const LVM_FINDITEM As Long = LVM_FIRST + 13
    Private Const LVM_ENSUREVISIBLE = LVM_FIRST + 19
    Private Const LVM_SETCOLUMNWIDTH As Long = LVM_FIRST + 30
    Private Const LVM_GETTOPINDEX = LVM_FIRST + 39
    Private Const LVM_SETITEMSTATE As Long = LVM_FIRST + 43
    Private Const LVM_GETITEMSTATE As Long = LVM_FIRST + 44
    Private Const LVM_GETITEMTEXT As Long = LVM_FIRST + 45
    Private Const LVM_SORTITEMS As Long = LVM_FIRST + 48
    Private Const LVM_SETEXTENDEDLISTVIEWSTYLE As Long = LVM_FIRST + 54
    Private Const LVM_GETEXTENDEDLISTVIEWSTYLE As Long = LVM_FIRST + 55
    Private Const LVM_SETCOLUMNORDERARRAY = LVM_FIRST + 58
    Private Const LVM_GETCOLUMNORDERARRAY = LVM_FIRST + 59Private Const LVS_EX_GRIDLINES As Long = &H1
    Private Const LVS_EX_SUBITEMIMAGES As Long = &H2
    Private Const LVS_EX_CHECKBOXES As Long = &H4
    Private Const LVS_EX_TRACKSELECT As Long = &H8
    Private Const LVS_EX_HEADERDRAGDROP As Long = &H10
    Private Const LVS_EX_FULLROWSELECT As Long = &H20Private Const LVFI_PARAM As Long = 1Private Const LVIF_TEXT As Long = 1
    Private Const LVIF_IMAGE As Long = 2
    Private Const LVIF_PARAM As Long = 4
    Private Const LVIF_STATE As Long = 8
    Private Const LVIF_INDENT As Long = &H10
    Private Const LVIF_NORECOMPUTE As Long = &H800
    Private Const LVIS_STATEIMAGEMASK As Long = &HF000&Private Type LV_ITEM
       Mask As Long
       Index As Long
       SubItem As Long
       State As Long
       StateMask As Long
       Text As String
       TextMax As Long
       Icon As Long
       Param As Long
       Indent As Long
    End TypePrivate Type LV_FINDINFO
       Flags As Long
       pSz As String
       lParam As Long
       pt As POINT
       vkDirection As Long
    End Type
    '--- Array used to speed custom sorts ---'
    Private m_lvSortData() As LV_ITEM
    Private m_lvSortColl As Collection
    Private m_lvSortColumn As Long
    Private m_lvHWnd As Long
    Private m_lvSortType As LVItemTypes'--- ListView Set Column Width Messages ---'
    Public Enum LVSCW_Styles
       LVSCW_AUTOSIZE = -1
       LVSCW_AUTOSIZE_USEHEADER = -2
    End EnumPublic Enum LVItemTypes
       lvDate = 0
       lvNumber = 1
       lvBinary = 2
       lvAlphabetic = 3
    End Enum
    Public Enum LVSortTypes
       lvAscending = 0
       lvDescending = 1
    End EnumPublic BuildLookup As Long
    Public PerformSort As LongPublic Function LVSortK(lv As ListView, ByVal Index As Long, ByVal ItemType As LVItemTypes, ByVal SortOrder As LVSortTypes) As Boolean
       Dim tmr As New CStopWatch
       
       ' turn off the default sorting of the control
       With lv
          .Sorted = False
          .SortKey = Index
          .SortOrder = SortOrder
       End With   ' store some values used during the sort
       m_lvSortColumn = Index
       m_lvSortType = ItemType
       m_lvHWnd = lv.hWnd
       BuildLookup = 0
       
       ' start sorting to type-specific callback routines
       tmr.Reset
       Select Case ItemType
          Case lvDate
             Call SendMessageLong(lv.hWnd, LVM_SORTITEMS, SortOrder, AddressOf LVCompareDates)
          Case lvNumber
             Call SendMessageLong(lv.hWnd, LVM_SORTITEMS, SortOrder, AddressOf LVCompareNumbers)
       End Select
       PerformSort = tmr.Elapsed
    End Function使用方法:
    ListView1.SortKey = ColumnHeader.Index - 1
    If ListView1.SortOrder = lvwAscending Then
    ListView1.SortOrder = lvwDescending
    Else
    ListView1.SortOrder = lvwAscending
    End If
    ListView1.Sorted = True
    '数值排序
    LVSortK ListView1, ListView1.SortKey, lvNumber, ListView1.SortOrder'日期排序:
    LVSortK ListView1, ListView1.SortKey, lvDate, ListView1.SortOrder
      

  3.   

    junwhj(junwhj.51.net) 的做法是可以的,也不是很慢。
    我就是真么做的。