|
回复 sgrshh29 的帖子
十、listview的操作
1、改变Listview显示样式
这里只选二种样式,大图标、报表
为按钮菜单添加过程
Sub mIcon()
Set objList = Forms("frmMain").Controls("Listview0")
objList.View = lvwIcon
pnlEditText "当前操作:ListView为Icon"
End Sub
Sub mReport()
Set objList = Forms("frmMain").Controls("Listview0")
objList.View = lvwReport
pnlEditText "当前操作:ListView为Report"
End Sub
2、编辑Listview的Item的文本并更新相应记录
为按钮菜单添加过程
Sub mEditeItem()
Dim strName As String
strName = InputBox("Typing New Name.", "Informationg")
If strName = "" Then Exit Sub
Set objTree = Forms("frmMain").Controls("treeview0")
Set objList = Forms("frmMain").Controls("Listview0")
pnlEditText "当前操作:编辑" & objList.SelectedItem
objList.SelectedItem.Text = strName
If objList.SelectedItem.SubItems(1) <> "" Then
CurrentDb.Execute "update tblListview set fname='" & strName & "' where id = " & Mid(objList.SelectedItem.Key, 2)
ElseIf objList.SelectedItem.SubItems(1) = "" Then
CurrentDb.Execute "update tblTreeview set pname='" & strName & "' where id = " & Mid(objList.SelectedItem.Key, 2)
objTree.Nodes("T" & Mid(objList.SelectedItem.Key, 2)).Text = strName
End If
pnlEditText "当前操作:编辑完成"
Set objTree = Nothing
Set objList = Nothing
End Sub
3、删除Listview的Item并且删除相应的记录
为按钮菜单添加过程
Sub mDeleteItem()
Dim objNode As Object
Dim strListKey As String
Set objTree = Forms("frmMain").Controls("treeview0")
Set objList = Forms("frmMain").Controls("Listview0")
If objList.SelectedItem Is Nothing Then Exit Sub '如果没有指定项目,就退出
pnlEditText "当前操作:正在删除" & objList.SelectedItem
strListKey = objList.SelectedItem.Key
If objList.SelectedItem.SubItems(1) = "" Then
strKey = "T" & Mid(strListKey, 2)
Set objNode = objTree.Nodes(strKey)
CurrentDb.Execute ("delete * from tblTreeview where id=" & Mid(strListKey, 2))
objList.ListItems.Remove (strListKey)
RemoveNode objNode
Else
strKey = "T" & DLookup("gid", "tblListview", "id=" & Mid(strListKey, 2))
Set objNode = objTree.Nodes(strKey)
CurrentDb.Execute ("delete * from tblListview where id=" & Mid(strListKey, 2))
objList.ListItems.Remove (strListKey)
End If
Set objNode = Nothing
Set objTree = Nothing
Set objLidt = Nothing
pnlEditText "当前操作:删除完成"
End Sub
4、改变listview的排序
为菜单按钮添加单击事件的过程
listview按文件名称排序
Sub mName()
Set objList = Forms("frmMain").Controls("Listview0")
objList.Sorted = True
objList.SortKey = 0
Set objList = Nothing
pnlEditText "当前操作:ListView按文件名称排序"
End Sub
listview按文件类型排序
Sub mType()
Set objList = Forms("frmMain").Controls("Listview0")
objList.Sorted = True
objList.SortKey = 1
Set objList = Nothing
pnlEditText "当前操作:ListView按文件类型排序"
End Sub
listview按最后修改日期排序
Sub mDate()
Set objList = Forms("frmMain").Controls("Listview0")
objList.Sorted = True
objList.SortKey = 3
Set objList = Nothing
pnlEditText "当前操作:ListView按文件修改日期排序"
End Sub
5、Listview的Item拖曳到Treeview的其它节点
a、在Listview0_OLEStartDrag事件中写入代码定义拖动类型
Private Sub Listview0_OLEStartDrag(Data As Object, AllowedEffects As Long)
strDragType = "ListView"
pnlEditText "当前操作:拖动ListviewItem。"
End Sub
b、在TreeView0_OLEDragDrop事件中判断出拖曳类型后执行代码
ElseIf strDragType = "ListView" Then '拖曳的是listrview的item
If Me.TreeView0.DropHighlight Is Nothing = False Then
If Me.TreeView0.SelectedItem.Key = Me.TreeView0.DropHighlight.Key Then Exit Sub
End If
Set objNode = Me.TreeView0.SelectedItem
ListDragDrop objNode
c、 ListDragDrop过程
Sub ListDragDrop(objNode As Node)
On Error GoTo Err_ListDragDrop
Dim i As Integer
Dim objTree As Object
Dim objList As Object
Dim nodDroped As Node
Set objTree = Forms("frmMain").Controls("treeview0").Object
Set objList = Forms("frmMain").Controls("listview0").Object
strKey = objList.SelectedItem.Key
With objList
If .SelectedItem.SubItems(1) <> "" Then
If objTree.DropHighlight Is Nothing Then
Exit Sub
Else
Set nodDroped = objTree.DropHighlight
End If
CurrentDb.Execute "update tblListview set gid = " & Mid(nodDroped.Key, 2) & _
" where id = " & Mid(strKey, 2)
.ListItems.Remove (strKey)
ElseIf .SelectedItem.SubItems(1) = "" Then
If objTree.DropHighlight Is Nothing Then
CurrentDb.Execute "update tblTreeview set gid=0 where id=" & Mid(strKey, 2)
加载Treeview Forms("frmMain").Controls("treeview0")
objTree.Nodes("T" & Mid(strKey, 2)).Selected = True
objTree.Nodes("T" & Mid(strKey, 2)).Expanded = True
加载ListItem strKey
Else
Set nodDroped = objTree.DropHighlight
CurrentDb.Execute "update tblTreeview set gid=" & Mid(nodDroped.Key, 2) & _
" where id=" & Mid(strKey, 2)
Set objTree.Nodes("T" & Mid(strKey, 2)).Parent = nodDroped
.ListItems.Remove (strKey)
End If
End If
End With
Exit_ListDragDrop:
Set objTree = Nothing
Set objList = Nothing
Set nodDroped = Nothing
Exit Sub
Err_ListDragDrop:
MsgBox Err.Description
Resume Exit_ListDragDrop
End Sub
6、完成以上步骤后的窗体演示
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|