0
votes

I have a userform where I want the user to be able to select multiple options, but am having a bit of a problem finding the best way to do this. If I use a combobox1, I don't appear to be able to allow multiple selections and Checkbox Option. I also want populate Combobox2 according to the selection made in combobox1.

I am trying with the below Code:

Private Sub UserForm_Initialize()
    Me.cbota1.AddItem "2A"
    Me.cbota1.AddItem "3Q"
    Me.cbota1.AddItem "Sim"
    Me.cbota1.AddItem "2T"
End Sub

Private Sub cbota1_Change()
    Dim index As Integer
    index = cbota1.ListIndex
    cbota2.Clear
    Select Case index
        Case Is = 0
            With cbota2
                .AddItem "Add dime"
                .AddItem "Add annot"
                .AddItem "Others"
                txtTo.Value = "AXA"
            End With

        Case Is = 1
            With cbota2
                .AddItem "Modify"
                .AddItem "Reduce"
                .AddItem "Others"
                txtTo.Value = "CA"
            End With
        Case Is = 2
            With cbota2
                .AddItem "Lin"
                .AddItem "Non"
                .AddItem "Mul"
                .AddItem "Vi"
                txtTo.Value = "ABA"
            End With
        Case Is = 3
            With cbota2
                .AddItem "Ad"
                .AddItem "Red"
                txtTo.Value = "A"
            End With      
    End Select
End Sub
1
The ComboBox control only allows one selection. You must use eg a ListBox control to allow multiple selections at once.Pᴇʜ
but if I use a listbox I don't appear to be able to implement a dropdown facility. I would prefer to have a single line sized box on my form, but doing this with a listbox would probably be confusing for the user.Santo
Well, but you cannot multi select in a ComboBox. It's a fact. And a ListBox is no drop down box. That is a fact too. So we can wait for someone inventing that for you or you must choose one of them. • By the way a multi select ComboBox would confuse the user even more, because ComboBoxes are always single select only (Basically a ComboBox is a TextBox where you can either select one of the pre defined texts (of the drop down list) or enter a new text.Pᴇʜ
Have a look at this - this might give you an alternative idea. You could use a ListBox instead of the TreeView linkTom
@Tom While this is possible it still would need to convert the multiple selections into eg a comma separated list to fit them into the TextBox. This approach would be no standard control behavior that a user would expect and even more confusing than using a simple ListBox. @ Santo I highly recommend to stick to standard controls (and how they are usually used in Windows) if you want your application to be intuitively. I mean what's wrong using a ListBox? I find nothing confusing with having a ListBox for multi select purpose. This is a very common usage.Pᴇʜ

1 Answers

0
votes

One solution I can think of, that is probably overkill is to open a second UserForm when you click on a Label or TextBox. In the new UserForm you could then list all of the items that can be selected in CheckBoxes and allow the user to select from there.

I briefly considered doing this once but decided against it due to the difficulty of passing the selections between the UserForms and the Moduls.