# Visual Basic > Visual Basic 6 and Earlier >  [RESOLVED] Omiiting a drive from a drivebox

## el84

I display a drivebox to allow the user to select a drive to backup to, and of course I don't want to include C in that drivebox. Is there a simple way to do that?

Currently I signal the user if the choice of destination is C and prevent them from proceeding. Works well, but I am still curious about whether one or more drives can be 'locked out' of a drivebox

----------


## fafalone

I think the easiest way for this would be to use a hidden drive list box and copy only what you want into a normal listbox/combobox.

I'm going to put a filter for my shell browser in the next version but currently it doesn't have an option to filter the drive list mode either.

----------


## el84

How do I do that. (Remember I am slower these days)

----------


## fafalone

The DriveListBox control has List and ListCount, so it's just like copying one ListBox to another. 



```
Private Sub Form_Load()
Dim i As Long
For i = 0 To Drive1.ListCount - 1
    If Left$(Drive1.List(i), 2) <> "c:" Then
        Combo1.AddItem Drive1.List(i)
    End If
Next i
Combo1.ListIndex = 0
End Sub
```

You'll lose the icons, but this is simplest solution. Obviously you could pursue nicer but more complicated ones.

----------


## dilettante

Lots of possible controls for something customized like this.  A TreeView or maybe MSHFlexGrid give you easy icon capabilities and the grid is even Unicode-aware.

----------


## Elroy

It would take a bit of snooping of the WM_??? messages, but I bet this would be fairly easy with just a bit of subclassing of the DriveListBox.  But I certainly haven't used that control in decades, not sure I ever have.

----------


## el84

Fafalone, I tried your suggestion, and this is my take



```
Option Explicit

Private Sub Form_Load()
    Dim i As Long
    For i = 0 To Drive1.ListCount - 1
        If Left$(Drive1.List(i), 2) <> "c:" Then Combo1.AddItem Drive1.List(i)
    Next i
    Combo1.ListIndex = 0
    Drive1.Visible = False
End Sub
```

As you can see, I have rendered the original drivelist invisible, leaving just the new combobox on the screen.
Interestingly, when I run that code the drivelist box only shows C but the combobox shows all my drives *except* C, which is what I wanted.

----------


## el84

Further to post #7, I have hit a snag which I think demolishes my hope for a 'simple' solution.
One of the properties of a drive list box is 'drive', which can be passed to a string variable for use when eg choosing to back up a file.
However, the nearest for a combo box is apparently 'text' which cannot be passed to a string variable, as far as I can see. (I've tried Variant and CStr -- no luck.
BTW Thanks for posts 5 and 6 but right over my head, I'm afraid!

----------


## fafalone

Combo1.List(Combo1.ListIndex)

----------


## techgnome

Hol up...



> However, the nearest for a combo box is apparently 'text' which cannot be passed to a string variable,


Of course it is a string... that's why it's called .Text ... it is the text of the selected item.  Now, depending on what the combobox style is, when you set the .Text it will either just take it as it is, or it'll try to find a matching item in its list (if not found ,then it'll blank out if I remember right). But either way .Text is a string.

-tg

----------


## el84

Fafalone, re post # 9, part of this (marked) does not work



```
Option Explicit
Dim Choice As String

Private Sub Form_Load()
    Dim i As Long
    For i = 0 To Drive1.ListCount - 1
        If Left$(Drive1.List(i), 2) <> "c:" Then Combo1.AddItem Drive1.List(i)
    Next i
    Combo1.ListIndex = 0
    Drive1.Visible = False
End Sub

Private Sub Combo1_Change()
    Changed = "Y"
    Choice = Left(Combo1.List(Combo1.ListIndex), 2)
    'apparently fails to pass the chosen drive details to the variable
End Sub

Private Sub Command1_Click() ' Debug just to test
    Debug.Print Left(Time, Len(Time) - 3) & " " & Left(Combo1.List(Combo1.ListIndex), 2) 'ok
    Debug.Print Left(Time, Len(Time) - 3) & " " & Choice 'not ok!
    Debug.Print String(13, "-")
 End Sub
```

----------


## fafalone

The Change event is for when you're typing in the combo edit box, it doesn't fire when you select something from the dropdown. Put Choice=... in Command1_Click instead.

----------


## el84

thanks, but the issue is the passing of the stuff to the Choice variable. See the debug.print comparison

EDIT! MANY APOLOGIES. got it!!
In fact I now see that I didn't need the change sub at all!

----------

