我现在想进行路径选择而不是文件选择
用commondialog行吗?
要设置什么属性?
不行的话
要用什么控件?
谢谢

解决方案 »

  1.   


    commondialog选择文件包括完整的路径 应该可以
    试试.FILENAME属性吧
      

  2.   

    Option ExplicitPrivate Type BrowseInfo
        hWndOwner As Long
        pIDLRoot As Long
        pszDisplayName As Long
        lpszTitle As Long
        ulFlags As Long
        lpfnCallback As Long
        lParam As Long
        iImage As Long
    End Type
    Const BIF_RETURNONLYFSDIRS = 1
    Const BIF_NEWDIALOGSTYLE = &H40
    Const BIF_EDITBOX = &H10
    Const MAX_PATH = 260Const BIF_BROWSEFORCOMPUTER = &H1000
     Const BIF_BROWSEFORPRINTER = &H2000
     Const BIF_BROWSEINCLUDEFILES = &H4000
     Const BIF_DONTGOBELOWDOMAIN = &H2
     Const BIF_RETURNFSANCESTORS = &H8
     Const BIF_STATUSTEXT = &H4
     Const BIF_USENEWUI = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX)
     
    Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    Private Sub Form_Load()
        Dim iNull As Integer, lpIDList As Long, lResult As Long
        Dim sPath As String, udtBI As BrowseInfo    With udtBI
            .hWndOwner = Me.hWnd
            .lpszTitle = lstrcat("C:\", "")
            .ulFlags = BIF_BROWSEINCLUDEFILES
        End With    lpIDList = SHBrowseForFolder(udtBI)
        If lpIDList Then
            sPath = String$(MAX_PATH, 0)
            SHGetPathFromIDList lpIDList, sPath
            CoTaskMemFree lpIDList
            iNull = InStr(sPath, vbNullChar)
            If iNull Then
                sPath = Left$(sPath, iNull - 1)
            End If
        End If    MsgBox sPath
    End Sub
      

  3.   

    可以使用DirListBox的Path属性
    如果使用CommonDialog必须选择文件,才可以得到带文件名的完整路径。
      

  4.   

    CommonDialog 控件可以显示如下常用对话框: “打开”
    “另存为”
    “颜色”
    “字体”
    “打印” 
    要使用 CommonDialog 控件 若未添加 CommonDialog 控件,则应从“工程”菜单中选定“部件”,将控件添加到工具箱中。在标记对话的“控件”中找到并选定控件,然后单击“确定”按钮。
    单击工具箱中的“CommonDialog”控件并在窗体上绘制该控件。 
    在窗体上绘制 CommonDialog 控件时,控件将自动调整大小。象 Timer 控件一样,CommonDialog 控件在运行时不可见。运行时,请适当使用下表所列方法显示需要的对话。 方法 显示的对话 
    ShowOpen 打开 
    ShowSave 另存为 
    ShowColor 颜色 
    ShowFont 字体 
    ShowPrinter 打印 
    ShowHelp 调用 Windows“帮助” 
      

  5.   

    做计算机之间串行通信的时候可以用这个控件取得文件
    然后弄到字节数组当中通过mscomm控件发送吗?
    如果可以 又该如何实现呢?
      

  6.   

    //怎么没人来些实际些的建议?你怎么不试试ch21st(www.blanksoft.com) 的代码,那段代码就是弹出一个选择文件夹的对话框,并返回文件夹的代码。
      

  7.   

    以下是一段类似代码:
    Bas COde 
    code:--------------------------------------------------------------------------------’This module contains all the declarations to use the
    ’Windows 95 Shell API to use the browse for folders
    ’dialog box. To use the browse for folders dialog box,
    ’please call the BrowseForFolders function using the
    ’syntax:  stringFolderPath=BrowseForFolders(Hwnd,TitleOfDial
    og)

    ’For contacting information, see other moduleOption ExplicitPublic Type BrowseInfo
         hwndOwner As Long
         pIDLRoot As Long
         pszDisplayName As Long
         lpszTitle As Long
         ulFlags As Long
         lpfnCallback As Long
         lParam As Long
         iImage As Long
    End TypePublic Const BIF_RETURNONLYFSDIRS = 1
    Public Const MAX_PATH = 260Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As LongPublic Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
          
        ’declare variables to be used
         Dim iNull As Integer
         Dim lpIDList As Long
         Dim lResult As Long
         Dim sPath As String
         Dim udtBI As BrowseInfo    ’initialise variables
         With udtBI
            .hwndOwner = hwndOwner
            .lpszTitle = lstrcat(sPrompt, "")
            .ulFlags = BIF_RETURNONLYFSDIRS
         End With    ’Call the browse for folder API
         lpIDList = SHBrowseForFolder(udtBI)
          
        ’get the resulting string path
         If lpIDList Then
            sPath = String$(MAX_PATH, 0)
            lResult = SHGetPathFromIDList(lpIDList, sPath)
            Call CoTaskMemFree(lpIDList)
            iNull = InStr(sPath, vbNullChar)
            If iNull Then sPath = Left$(sPath, iNull - 1)
         End If    ’If cancel was pressed, sPath = ""
         BrowseForFolder = sPathEnd Function
    Form Code Private Sub cmdServerBrowse_Click()
     txtDatabasePath.Text = BrowseForFolder(hwnd, "Please select a Server folder.")
    End Sub
      

  8.   

    同意二楼的,就是用这些api
    你运行就知道了
    Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
            "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPrivate Declare Function SHGetSpecialFolderLocation Lib _
            "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder _
            As Long, pIdl As ITEMIDLIST) As LongPrivate Declare Function SHGetFileInfo Lib "Shell32" Alias _
            "SHGetFileInfoA" (ByVal pszPath As Any, ByVal _
            dwFileAttributes As Long, psfi As SHFILEINFO, ByVal _
            cbFileInfo As Long, ByVal uFlags As Long) As LongPrivate Declare Function ShellAbout Lib "shell32.dll" Alias _
            "ShellAboutA" (ByVal hwnd As Long, ByVal szApp As _
            String, ByVal szOtherStuff As String, ByVal hIcon As Long) _
            As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
            Alias "SHGetPathFromIDListA" (ByVal pIdl As Long, ByVal _
            pszPath As String) As Long
    Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)Const MAX_PATH = 260Private Type SHITEMID
        cb As Long
        abID() As Byte
    End TypePrivate Type ITEMIDLIST
        mkid As SHITEMID
    End TypePrivate Type BROWSEINFO
        hOwner As Long
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As Long
        lParam As Long
        iImage As Long
    End TypePrivate Type SHFILEINFO
        hIcon As Long
        iIcon As Long
        dwAttributes As Long
        szDisplayName As String * MAX_PATH
        szTypeName As String * 80
    End Type
    Private Function GetFolderValue(wIdx As Integer) As Long
        If wIdx < 2 Then
            GetFolderValue = 0
        ElseIf wIdx < 12 Then
            GetFolderValue = wIdx
        Else
            GetFolderValue = wIdx + 4
        End If
    End FunctionPrivate Sub Command1_Click()
      Dim BI As BROWSEINFO
      Dim nFolder As Long
      Dim IDL As ITEMIDLIST
      Dim pIdl As Long
      Dim sPath As String
      Dim SHFI As SHFILEINFO
      Dim m_wCurOptIdx As Integer
      Dim txtPath As String
      Dim txtDisplayName As String
      
      With BI
        .hOwner = Me.hwnd
        nFolder = GetFolderValue(m_wCurOptIdx)
        
        If SHGetSpecialFolderLocation(ByVal Me.hwnd, ByVal nFolder, IDL) = NOERROR Then
          .pidlRoot = IDL.mkid.cb
        End If
        
        .pszDisplayName = String$(MAX_PATH, 0)
        .lpszTitle = "Browsing is limited to: "
        .ulFlags = 0
      End With
      
      txtPath = ""
      txtDisplayName = ""
      
      pIdl = SHBrowseForFolder(BI)
      
      If pIdl = 0 Then Exit Sub
      sPath = String$(MAX_PATH, 0)
      SHGetPathFromIDList ByVal pIdl, ByVal sPath  txtPath = Left(sPath, InStr(sPath, vbNullChar) - 1)
      txtDisplayName = Left$(BI.pszDisplayName, _
                        InStr(BI.pszDisplayName, vbNullChar) - 1)
      
      SHGetFileInfo ByVal pIdl, 0&, SHFI, Len(SHFI), _
                    SHGFI_PIDL Or SHGFI_ICON Or SHGFI_SMALLICON
      
      SHGetFileInfo ByVal pIdl, 0&, SHFI, Len(SHFI), _
                    SHGFI_PIDL Or SHGFI_ICON
      CoTaskMemFree pIdl
      MsgBox "你选择的文件夹是" + Chr(13) + Chr(10) + txtPath
    End Sub
      

  9.   

    借楼主地盘 请先看一下 以下 
    Private Sub Command2_Click()  Dim rsTest As New ADODB.Recordset
      Dim strSQL As String  strSQL = "select * from DE where 分件号 like '%" + Text4.Text + "%'"
      rsTest.Open strSQL, GCon
      If rsTest.RecordCount = 0 Then
      MsgBox "没有找到匹配记录!", vbInformation, "提示"
      Else
      Set DataGrid1.DataSource = rsTest
      End If好,问题 来了
    请问,我要如何写 才能用鼠标 点选 某条查询出来的记录时 同时把 该条记录中的某3个字段的值分别显示在3个不同的Text 上呢??
      

  10.   

    谢谢kissoflife的提示
    原来是可以的
    我原来试过好像不行
    谢谢了!
    问题解决