当前位置:编程学习 > VB >>

目录树怎么打开本地文件?

Private Sub LoadFromTable()
'asks the user to find the database and then restores the Nodes
'in the treeview control from the table
    Dim oNodex As Node
    Dim nImage As Integer
    Dim nSelectedImage As Integer
    Dim i As Integer
    Dim sTableNames As String
    Dim sNodeTable As String
    
    MsgBox "请选择数据库:"
    nImage = 0
    nSelectedImage = 0
    CommonDialog1.Filter = "Access Database (*.MDB)|* .mdb"
    CommonDialog1.ShowOpen
    If Len(CommonDialog1.FileName) < 1 Then
        MsgBox ("没有文件选择")
        Exit Sub
    End If
    
    Set mDB = DBEngine.Workspaces(0).OpenDatabase(CommonDialog1.FileName)
    For i = 0 To mDB.TableDefs.Count - 1 'TableDefs is a 0 based collection
        If Left(mDB.TableDefs(i).Name, 4) <> "MSys" Then
            sTableNames = sTableNames & mDB.TableDefs(i).Name & ", "
        End If
    Next
    sNodeTable = InputBox(sTableNames, "请输入数据库名")
    'Set mrs = db.OpenRecordset("loadnodes")
    'Debug.Print
    TreeView1.Nodes.Clear 'Clear the TreeView of any nodes
    Set mRS = mDB.OpenRecordset(sNodeTable)
    If mRS.RecordCount > 0 Then 'make sure there are records in the table
        mRS.MoveFirst
        Do While mRS.EOF = False
            nImage = mRS.Fields("image")
            nSelectedImage = mRS.Fields("selectedimage")
            If Trim(mRS.Fields("parent")) = "0_" Then 'All root nodes have 0_ in the parent field
                Set oNodex = TreeView1.Nodes.Add(, 1, Trim(mRS.Fields("key")), _
                  Trim(mRS.Fields("text")), nImage, nSelectedImage)
            Else 'All child nodes will have the parent key stored in the parent field
                Set oNodex = TreeView1.Nodes.Add(Trim(mRS.Fields("parent")), tvwChild, _
                   Trim(mRS.Fields("key")), Trim(mRS.Fields("text")), nImage, nSelectedImage)
                oNodex.EnsureVisible 'expend the TreeView so all nodes are visible
            End If
            mRS.MoveNext
        Loop
    End If
    mRS.Close 'Close the table
    mDB.Close 'Close the database
End Sub


目录树做了增加删除和修改,这是从access数据库里提取到的数据,放在目录树里,怎么在目录树的各节点上能打开本地文件?什么类型的都可,具体代码怎么实现?希望越详细越好哈,谢谢!! --------------------编程问答--------------------
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    Select Case Node.Index
      Case 1
         shell "d:\a.txt"  '打开文件
      case 2
      Case 3
      Case 4
    end select
End Sub
--------------------编程问答-------------------- 不好意思,没有看明白,2,3,4都写啥呢,对不起,我是初学者,不太会啊 --------------------编程问答-------------------- ' nShowCmd
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
'以上在.bas中

ShellExecute Me.hwnd, vbNullString, 路径及文件名, vbNullString, vbNullString, 5 --------------------编程问答--------------------
引用 2 楼 laomao686 的回复:
不好意思,没有看明白,2,3,4都写啥呢,对不起,我是初学者,不太会啊

--------------------编程问答-------------------- 好的,谢谢楼上各位,让大家见笑了,我试试哦:> --------------------编程问答-------------------- ShellExecute Me.hwnd, vbNullString, "d:\test.txt", vbNullString, vbNullString, 5
===
上面的一行运行就出错,这一行我应该写在哪里呢?
还有,运行完就能指到目录树的相应节点吗? --------------------编程问答-------------------- 我测试是可以的!
错误提示是什么?
最后一个问题:不行!执行外部程序,所以... --------------------编程问答-------------------- 是呀,错误提示:无效的外部程序
下一部我应该怎么做呢? --------------------编程问答--------------------
引用 2 楼 laomao686 的回复:
不好意思,没有看明白,2,3,4都写啥呢,对不起,我是初学者,不太会啊

2,3,4等代表目录树的子项索引(Node.Index)
--------------------编程问答-------------------- 谢谢专家们!
现在就不知道怎么将树里面的对象与文件关联,在一个窗口上设置一下,存到数据库中呢 --------------------编程问答-------------------- 借鉴 “资源管理器” 的格式 --------------------编程问答--------------------
引用 8 楼 laomao686 的回复:
是呀,错误提示:无效的外部程序
下一部我应该怎么做呢?

你换xls doc 之类的试试,也许、可能、或者你的txt没有关联到应用程序吧!????? --------------------编程问答-------------------- 还有。有一个叫vbExplorer的源码,网上可以下的,你找看看。

不过,它是完全调用windows资源管理器的内容,不太容易看懂就是了... --------------------编程问答-------------------- 要是目录树可以打开文件,那么汽车钥匙就可以载客旅行。 --------------------编程问答-------------------- 目录树不能打开本地文件么?有人试过没有啊···我现在目录树编出来了,可就是不能打开里面的文件,请高手指教啊!!!
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,