简单的问题:请教怎么样设置ListView控件的图标?

sumy 2004-04-29 06:54:48

怎么样才能让ListView的View属性设为3-lvwReport样式,但又在每一项之前显示一个图标呢?

我用imagelist控件连接listview来实现,可是好像只有在View设为1-lvwIcon才可以,设成3后图标就不出来了。
...全文
26 7 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
flyingZFX 2004-04-30
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
  • 打赏
  • 举报
回复
sumy 2004-04-30

daisy8675(莫依) 大哥,偶真的不懂你的代码呀,可不可以举个例子告诉我呀?!
  • 打赏
  • 举报
回复
tangxiaosan001 2004-04-30
haha .
  • 打赏
  • 举报
回复
daisy8675 2004-04-30
隨便你怎麼放阿,那不是個函數呀...我汗

是寫法
  • 打赏
  • 举报
回复
sumy 2004-04-29

顶一下~
  • 打赏
  • 举报
回复
sumy 2004-04-29

不好意思,请问上面的函数如何调用?
  • 打赏
  • 举报
回复
daisy8675 2004-04-29
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 = Nothing

End Sub
  • 打赏
  • 举报
回复
相关推荐
发帖
控件
加入

1432

社区成员

VB 控件
社区管理员
  • 控件
申请成为版主
帖子事件
创建了帖子
2004-04-29 06:54
社区公告
暂无公告