Results 1 to 5 of 5

Thread: List Boxes Aarrggh!! Help

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    8

    List Boxes Aarrggh!! Help

    Hello,

    Right i have two forms. One the first is a drive list box. I want this to only display hard-disks, not CDROMS or A:\ or Removeable drives. Anyone know how to do this?

    Plus on my form2 is a directory list box, i want this list box to show the users chosen hard-disk, open at "Documents and Settings".. So if a user chooses "c:\" the directory list box on form2 will open at "C:\Documents and Settings".. Anyone know how to do this?..

    PLEASE HELP.

    MAIL ME HERE

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List Boxes Aarrggh!! Help

    Moved from CodeBank.

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: List Boxes Aarrggh!! Help

    Hi jonnie and welcome to VBForums!
    Imfortunately what you described doesn't make much sense to me - if you restrict user from browsing anything but his/her personal folders then why ever bother showing navigation tools such drive/dir listboxes. Also "Documents And Setttings" is Windows special folder and it could have a different name on different system so you need to find it. The following sample is a modified sample from allapi network - it demonstrates how to find personal folder. You may use that path throughout the project but variable will have to be declare as Public at the module level.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const CSIDL_PERSONAL = &H5
    4. Private Const ERROR_SUCCESS = 0&
    5.  
    6. Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
    7.     (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
    8.  
    9. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
    10.     Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    11.  
    12. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
    13.  
    14. Private Sub Command1_Click()
    15. Dim strPath$
    16.  
    17.     strPath = GetSpecialFolder(Me.hwnd, CSIDL_PERSONAL)
    18.     Debug.Print "Desktop folder: " & strPath
    19.  
    20. End Sub
    21.  
    22. Public Function GetSpecialFolder(hwnd As Long, CSIDL As Long) As String
    23. '========================================================================
    24. Dim pidl As Long
    25. Dim Pos As Long
    26. Dim sPath As String
    27.      
    28.     'fill the pidl with the specified folder item
    29.     If SHGetSpecialFolderLocation(hwnd, CSIDL, pidl) = ERROR_SUCCESS Then
    30.         'initialize & get the path
    31.         sPath = Space$(260)
    32.         If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
    33.             'check for a null
    34.             Pos = InStr(sPath, Chr$(0))
    35.             If Pos Then 'strip it
    36.                 GetSpecialFolder = Left$(sPath, Pos - 1)
    37.             End If
    38.             Call CoTaskMemFree(pidl)
    39.         End If
    40.     End If
    41.    
    42. End Function

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    8

    Re: List Boxes Aarrggh!! Help

    I have sorted out opening the dirlistbox at "chosen source drive"\Documents and settings,

    NOW,

    I want to make the UNC of [chosenSourceDrive]\Documents and Settings to be the top most folder in the dirListBox.

    Anyone know how to do this?

    Would I use the TopIndex property and set a string value to it?

    Such as... (pseudo)

    'Source Drive Form
    #################
    text1.text = [chosen source drive letter] + \Documents and Settings

    'Text 1 Now reads "C:\Documents and Settings
    'My dirListBox on my "Choose your username" form is set to that path.

    'UserName Form
    ############
    'OK Heres the bit i'm struggling with, so take the info that there are two
    'forms, on the first one, the user chooses a drive and the drive letter plus
    '\documents and settings is set to a text box. That text box is read into
    'the dirListBox as the path, hecnce the dirListBox opens at "drive" +
    '\documents and setting
    'You See... (take the symbol "@" to mean a folder icon)
    @c:\
    @Documents and Settings
    @username1
    @username2
    @username3

    i want the usernames to be the top most folder so it just shows

    @username1
    @username2
    @username3

    Any one help?

  5. #5
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: List Boxes Aarrggh!! Help

    Quote Originally Posted by jonniehack
    I have sorted out opening the dirlistbox at "chosen source drive"\Documents and settings,

    NOW,

    I want to make the UNC of [chosenSourceDrive]\Documents and Settings to be the top most folder in the dirListBox.

    Anyone know how to do this?

    Would I use the TopIndex property and set a string value to it?

    Such as... (pseudo)

    'Source Drive Form
    #################
    text1.text = [chosen source drive letter] + \Documents and Settings

    'Text 1 Now reads "C:\Documents and Settings
    'My dirListBox on my "Choose your username" form is set to that path.

    'UserName Form
    ############
    'OK Heres the bit i'm struggling with, so take the info that there are two
    'forms, on the first one, the user chooses a drive and the drive letter plus
    '\documents and settings is set to a text box. That text box is read into
    'the dirListBox as the path, hecnce the dirListBox opens at "drive" +
    '\documents and setting
    'You See... (take the symbol "@" to mean a folder icon)
    @c:\
    @Documents and Settings
    @username1
    @username2
    @username3

    i want the usernames to be the top most folder so it just shows

    @username1
    @username2
    @username3

    Any one help?
    You'd probably have to do it through API - I'm not shure that VB has a way to re-order thigs in a list box as a built in method.

    Did you try RhinoBull's method, it could be much easier

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width