怎么样才能让ListView的View属性设为3-lvwReport样式,但又在每一项之前显示一个图标呢?我用imagelist控件连接listview来实现,可是好像只有在View设为1-lvwIcon才可以,设成3后图标就不出来了。

解决方案 »

  1.   

    Public Sub LoadLvwData(Node As Node)  If Rs.State <> adStateClosed Then Rs.Close
      
      With Me.ListView1
        .ListItems.Clear
        .View = lvwReport
        .SmallIcons = Me.ImageList1  '--設置你對應的imagelist,是smallicon對應    .ColumnHeaders.Clear
      End With
       Rs.Open "Select * from People", Conn, adOpenKeyset, adLockPessimistic  With ListView1.ColumnHeaders
        .Add , , "Name"
        .Add , , "Class"
      End With
      
      Do While Not Rs.EOF
        Set Itmx = Me.ListView1.ListItems.Add(, , Trim(IIf(IsNull(Rs("Name")), "", Rs("Name"))), , 1)  '--1代表imagelist中的第1個圖象,也就是你想設置的圖標
            Itmx.SubItems(1) = Trim(IIf(IsNull(Rs("Class")), "", Rs("Class")))
            Itmx.Tag = Trim("" & Rs("ID"))
     
            Rs.MoveNext
      Loop  Set Rs = Nothing
      Set Itmx = NothingEnd Sub
      

  2.   

    Private Sub Form_Load()
            On Error GoTo err1
            
            Dim obj_File As FileSystemObject
            Dim Cur_Folder As Folder
            Dim Cur_Files As Files
            Dim Cur_File As File
            Dim cur_DBListItem As ListItem
            
            Me.Icon = HelpWindowIcon.Picture
            Call ModReSizeForm.ResizeInit(Me)
            ImageList1.ListImages.Add , , Image1.Picture
            With List_DB_Bak
                 .ColumnHeaders.Add , , "备份文件名", 3000
                 .ColumnHeaders.Add , , "文件建立时间", 3000
                 .SmallIcons = Me.ImageList1
                 .View = lvwReport
                 .GridLines = True
                 .FullRowSelect = True
                 .LabelEdit = lvwManual
                 .HideSelection = False
                 .SortKey = Me.List_DB_Bak.ColumnHeaders(1).Index
                 .SortOrder = lvwAscending
                 .Sorted = True
                 .ListItems.Clear
            End With
            Set obj_File = CreateObject("Scripting.FileSystemObject")
            If obj_File.FolderExists(App.Path & "\DB_Bak") = True Then
                  Set Cur_Folder = obj_File.GetFolder(App.Path & "\DB_Bak")
                  Set Cur_Files = Cur_Folder.Files
                  If Cur_Files.Count <> 0 Then
                       For Each Cur_File In Cur_Files
                            If Right$(Cur_File.Name, 3) = "ZIP" Or Right$(Cur_File.Name, 3) = "zip" Or Right$(Cur_File.Name, 3) = "Zip" Then
                                  Set cur_DBListItem = List_DB_Bak.ListItems.Add(, Cur_File.Name, Left$(Cur_File.Name, Len(Cur_File.Name) - 4), , 1)
                                  With cur_DBListItem
                                       .SubItems(1) = Format$(Cur_File.DateCreated, "yyyy-mm-dd hh:mm:ss")
                                  End With
                                  Set cur_DBListItem = Nothing
                            End If
                       Next Cur_File
                       Me.List_DB_Bak.Refresh
                       Me.cmd_DelAll_Bak_DB.Enabled = True
                  Else
                       Me.List_DB_Bak.Enabled = False
                  End If
            End If
            Set Cur_File = Nothing
            Set Cur_Files = Nothing
            Set Cur_Folder = Nothing
            Set obj_File = Nothing
    err1:
            If Err.Number <> 0 Then
                  Error_Send Err
            End If
            
    End Sub
      

  3.   


    daisy8675(莫依) 大哥,偶真的不懂你的代码呀,可不可以举个例子告诉我呀?!