我有一个grid,其中有一列存储着文件的绝对路径.
这些文件可能是word文件,可能是txt,可能是xls等类型.我如何通过双击grid的某一行来打开相对应的文件?谢谢

解决方案 »

  1.   

    取得这列的文件名,然后shell
      

  2.   

    在 grid 的 DblClick() 事件中处理呀。
      

  3.   

    Dim aa$
    Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
       aa = Adodc1.Recordset.Fields(3)
    End SubPrivate Sub Command1_Click()
       Shell "explorer " & aa, vbMaximizedFocus
    End Sub
      

  4.   

    shell 是不是好像只能用于打开exe这类可执行文件的啊?explorer好像可以.但是如果是word文档的话,系统会弹出对话框说是要打开还是保存.而txt文件的话,就会直接显示在ie窗口里面.没试过,如果机器上只装了firefox的话,会不会有问题?
      

  5.   

    用API:ShellExecute
    Private Declare Function GetDesktopWindow Lib "user32" () As LongPrivate Declare Function ShellExecute Lib "shell32" _
        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
        Dim aa$ 
    Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer) 
       aa = Adodc1.Recordset.Fields(3) 
    End Sub Private Sub Command1_Click() 
     ShellExecute GetDesktopWindow ,"open",aa,0,0,1
    End Sub