看看它的View 和 Sorting 以及 Arrange属性满足你的要求

解决方案 »

  1.   

    图标不用调整位置就可以对齐排列。按某索引排列等可以在向ListView中添加数据的语句中实现
      

  2.   

    ListView的Arrange属性好象只有vbArrangeLeft和vbArrangeTop;
      

  3.   

    http://www.dapha.net/VB/list.asp?id=1188
    http://www.dapha.net/VB/list.asp?id=1188
    http://www.dapha.net/VB/list.asp?id=1188
      

  4.   

    http://www.dapha.net/VB/list.asp?id=1188
    http://www.dapha.net/VB/list.asp?id=1188
    http://www.dapha.net/VB/list.asp?id=1188
      

  5.   

    http://www.dapha.net/VB/list.asp?id=1188
    http://www.dapha.net/VB/list.asp?id=1188
    http://www.dapha.net/VB/list.asp?id=1188
      

  6.   

    ListView1.View = lvwReport
      

  7.   

    HOWTO: Sort a ListView Control by Date
    Last reviewed: July 1, 1997
    Article ID: Q170884  
    The information in this article applies to: 
    Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0 
    SUMMARY
    When using a Listview control, you can set the Sorted property for the control to sort the list alphabetically. However, the Listview control does not expose a property or method for sorting a list by date. This article presents a method that you can use to sort a Listview control by date. MORE INFORMATION
    To sort data in a ListView control by date, it is necessary to provide a comparison function to the control via AddressOf. NOTE: Using this approach, you will sort the data in the control but not the ListItems collection. Therefore, if you must read the data from the list in sorted order, it is necessary to step through the actual list rather than the ListItems collection. Step-by-Step ExampleStart a new Visual Basic project. Form1 is created by default. Click Components on the Project menu. Check "Microsoft Windows Common Controls 5.0" and click OK. Add a Module to the project. Draw a ListView control on Form1. Add the following code to Form1: 
          Option Explicit      Private Sub Form_Load()
            Dim clmAdd As ColumnHeader
            Dim itmAdd As ListItem
       
            'Add two Column Headers to the ListView control
            Set clmAdd = ListView1.ColumnHeaders.Add(Text:="Name")
            Set clmAdd = ListView1.ColumnHeaders.Add(Text:="Date")
       
            'Set the view property of the Listview control to Report view
            ListView1.View = lvwReport
       
            'Add data to the ListView control
            Set itmAdd = ListView1.ListItems.Add(Text:="Joe")
            itmAdd.SubItems(1) = "05/07/97"
       
            Set itmAdd = ListView1.ListItems.Add(Text:="Sally")
            itmAdd.SubItems(1) = "04/08/97"
       
            Set itmAdd = ListView1.ListItems.Add(Text:="Bill")
            itmAdd.SubItems(1) = "05/29/97"
       
            Set itmAdd = ListView1.ListItems.Add(Text:="Fred")
            itmAdd.SubItems(1) = "05/17/97"        Set itmAdd = ListView1.ListItems.Add(Text:="Anne")
            itmAdd.SubItems(1) = "04/01/97"
       
          End Sub
       
          Private Sub ListView1_ColumnClick(ByVal ColumnHeader As _
                  ComctlLib.ColumnHeader)
            Dim strName As String
            Dim dDate As Date
            Dim lngItem As Long
       
            'Handle User click on column header
            If ColumnHeader.Tag = "Name" Then  'User clicked on Name header
              ListView1.Sorted = True        'Use default sorting to sort the
              ListView1.SortKey = 0          'items in the list
            Else
              ListView1.Sorted = False       'User clicked on the Date header
                                             'Use our sort routine to sort
                                             'by date
              SendMessage ListView1.hWnd, _
                          LVM_SORTITEMS, _
                          ListView1.hWnd, _
                          AddressOf CompareDates
            End If
       
            'Refresh the ListView before writing the data
            ListView1.Refresh
       
            'Loop through the items in the List to print them out in
            'sorted order.
            'NOTE: You are looping through the ListView control because when _
            'sorting by date the ListItems collection won't be sorted.
       
            For lngItem = 0 To ListView1.ListItems.Count - 1
              ListView_GetListItem lngItem, ListView1.hWnd, strName, dDate
            Next
       
          End Sub
    Add the following code to Module1: 
          Option Explicit      'Structures      Public Type POINT
            x As Long
            y As Long
          End Type
       
          Public Type LV_FINDINFO
            flags As Long
            psz As String
            lParam As Long
            pt As POINT
            vkDirection As Long
          End Type
       
          Public Type LV_ITEM
            mask As Long
            iItem As Long
            iSubItem As Long
            State As Long
            stateMask As Long
            pszText As Long
            cchTextMax As Long
            iImage As Long
            lParam As Long
            iIndent As Long
          End Type
       
      

  8.   

    'Constants
          Private Const LVFI_PARAM = 1
          Private Const LVIF_TEXT = &H1
       
          Private Const LVM_FIRST = &H1000
          Private Const LVM_FINDITEM = LVM_FIRST + 13
          Private Const LVM_GETITEMTEXT = LVM_FIRST + 45
          Public Const LVM_SORTITEMS = LVM_FIRST + 48      'API declarations
          Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
            ByVal hWnd As Long, _
            ByVal wMsg As Long, _
            ByVal wParam As Long, _
            ByVal lParam As Long) As Long      'Module Functions and Procedures
       
          'CompareDates: This is the sorting routine that gets passed to the
          'ListView control to provide the comparison test for date values.
       
          Public Function CompareDates(ByVal lngParam1 As Long, _
                                       ByVal lngParam2 As Long, _
                                       ByVal hWnd As Long) As Long
       
            Dim strName1 As String
            Dim strName2 As String
            Dim dDate1 As Date
            Dim dDate2 As Date
       
            'Obtain the item names and dates corresponding to the
            'input parameters
       
            ListView_GetItemData lngParam1, hWnd, strName1, dDate1
            ListView_GetItemData lngParam2, hWnd, strName2, dDate2
       
            'Compare the dates
            'Return 0 ==> Less Than
            '       1 ==> Equal
            '       2 ==> Greater Than
       
            If dDate1 < dDate2 Then
              CompareDates = 0
            ElseIf dDate1 = dDate2 Then
              CompareDates = 1
            Else
              CompareDates = 2
            End If
       
          End Function      'GetItemData - Given Retrieves
       
          Public Sub ListView_GetItemData(lngParam As Long, _
                                          hWnd As Long, _
                                          strName As String, _
                                          dDate As Date)
            Dim objFind As LV_FINDINFO
            Dim lngIndex As Long
            Dim objItem As LV_ITEM
            Dim baBuffer(32) As Byte
            Dim lngLength As Long
       
            '
            ' Convert the input parameter to an index in the list view
            '
            objFind.flags = LVFI_PARAM
            objFind.lParam = lngParam
            lngIndex = SendMessage(hWnd, LVM_FINDITEM, -1, VarPtr(objFind))
       
            '
            ' Obtain the name of the specified list view item
            '
            objItem.mask = LVIF_TEXT
            objItem.iSubItem = 0
            objItem.pszText = VarPtr(baBuffer(0))
            objItem.cchTextMax = UBound(baBuffer)
            lngLength = SendMessage(hWnd, LVM_GETITEMTEXT, lngIndex, _
                                    VarPtr(objItem))
            strName = Left$(StrConv(baBuffer, vbUnicode), lngLength)
       
            '
            ' Obtain the modification date of the specified list view item
            '
            objItem.mask = LVIF_TEXT
            objItem.iSubItem = 1
            objItem.pszText = VarPtr(baBuffer(0))
            objItem.cchTextMax = UBound(baBuffer)
            lngLength = SendMessage(hWnd, LVM_GETITEMTEXT, lngIndex, _
                                    VarPtr(objItem))
            If lngLength > 0 Then
              dDate = CDate(Left$(StrConv(baBuffer, vbUnicode), lngLength))
            End If
       
          End Sub      'GetListItem - This is a modified version of ListView_GetItemData
          ' It takes an index into the list as a parameter and returns
          ' the appropriate values in the strName and dDate parameters.
       
          Public Sub ListView_GetListItem(lngIndex As Long, _
                                          hWnd As Long, _
                                          strName As String, _
                                          dDate As Date)
            Dim objItem As LV_ITEM
            Dim baBuffer(32) As Byte
            Dim lngLength As Long
       
            '
            ' Obtain the name of the specified list view item
            '
            objItem.mask = LVIF_TEXT
            objItem.iSubItem = 0
            objItem.pszText = VarPtr(baBuffer(0))
            objItem.cchTextMax = UBound(baBuffer)
            lngLength = SendMessage(hWnd, LVM_GETITEMTEXT, lngIndex, _
                                    VarPtr(objItem))
            strName = Left$(StrConv(baBuffer, vbUnicode), lngLength)
       
            '
            ' Obtain the modification date of the specified list view item
            '
            objItem.mask = LVIF_TEXT
            objItem.iSubItem = 1
            objItem.pszText = VarPtr(baBuffer(0))
            objItem.cchTextMax = UBound(baBuffer)
            lngLength = SendMessage(hWnd, LVM_GETITEMTEXT, lngIndex, _
                                    VarPtr(objItem))
            If lngLength > 0 Then
              dDate = CDate(Left$(StrConv(baBuffer, vbUnicode), lngLength))
            End If
       
          End Sub
    Save your project. Press the F5 key to run the application. Click on the Date column header to sort the items in the list by date.  
      

  9.   

    Private Sub ListView1_ColumnClick(ByVal ColumnHeader As ColumnHeader)
       ListView1.SortKey = ColumnHeader.Index - 1   ListView1.Sorted = TrueEnd Sub
      

  10.   

    感谢您使用微软产品。  在ListView中,您可以通过以下方法实现您要的功能:1、  对齐图标:
    您可以类似资源管理器的做法,将ListView区分为多个网格,然后通过一个循环将他们对齐到里他们最近的网格即可。您可以参考以下代码:Dim i As Integer
           For i = 1 To ListView1.ListItems.Count
           ListView1.ListItems.Item(i).Top = Round((ListView1.ListItems.Item(i).Top - 30) / 1365) * 1365 + 30
           ListView1.ListItems.Item(i).Left = Round((ListView1.ListItems.Item(i).Left - 30) / 1365) * 1365 + 30
        Next i此时使用的是48*48的大图标,您还需要注意的是增加一些代码控制是否会出现图标重叠的情况。您可以用数组记录位置信息来实现。2、  自动排列:
    您可以设置listview的arrange属性,代码如下:
    ListView1.Arrange = lvwAutoLeft
    或者ListView1.Arrange = lvwAutoTop,如果要取消排列,则设置ListView1.Arrange = lvwNone,在使用lvwAutoTop时,将不会自动排列到ListView的最顶端 3,按某索引排列:
    如果您对于项的名称进行排列,只需要设置其属性如下:
    ListView1.SortKey = 0
    ListView1.SortOrder = lvwDescending / lvwAscending
    ListView1.Sorted = True如果您的Item具有其他的属性,而您又希望对这些属性进行排序的话,那么您必须自行写代码存储并将这些Item的顺序,然后手动加入。您可以参考如下代码:‘对ListView中的Item进行排序
    public function Sort(index as Long)
    ‘根据需要的内容进行排序
    end function‘清除原来的内容
    MaxSize= ListView1.ListItems.Count
    For i = 1 To MaxSize
        ListView1.ListItems.Remove (1)
    Next i
    ‘增加新的内容
    For i=1 to MaxSize
        ListView1.ListItems.Add …..’增加相应的内容
    Next i
    您可以参考
    ListView Control(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmctl198/html/vbobjlistview.asp )学习ListView的使用。 用VB6中的ListView控件实现像资源管理器一样的功能,并不是一件非常方便的事情;您可以尝试使用Visual Stdio.NET中的ListView Control来实现您需要的功能。
    请参考:
    Visual Basic and Visual C# Concepts   ListView Control (Windows Forms)( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriListViewCtlTasks.asp )来学习.NET中ListView Control的使用。微软全球技术中心 VB技术支持
    本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。