disable entry on listbox

S

Smallweed

Can I selectively disable an individual entry on a multiselect listbox in a
userform? If so, how?

Thanks
 
I

Incidental

Hi Smallweed

The code below should sort of do what you want it will check if your
item has been clicked and if so it will deselect it.

Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)

If ListBox1.Selected(3) = True Then

ListBox1.Selected(3) = False

End If

End Sub

Hope this helps

Steve
 
D

Dave Peterson

How about just not including it in the listbox to start--or removing it when it
shouldn't be selected?

Or even just ignore it if it is selected?

But if you want...

Option Explicit
Dim BlkProc As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim iCtr As Long
With Me.ListBox1
For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) = True Then
MsgBox iCtr & "--" & .List(iCtr)
End If
Next iCtr
End With
End Sub
Private Sub ListBox1_Change()

Dim ItemToBeAvoided As Long

If BlkProc = True Then
Exit Sub
End If

ItemToBeAvoided = 2 'third item (0 based)

If Me.ListBox1.Selected(ItemToBeAvoided) = True Then
BlkProc = True
Me.ListBox1.Selected(ItemToBeAvoided) = False
BlkProc = False
End If

End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
For iCtr = 1 To 5
.AddItem "A" & iCtr
Next iCtr
End With
End Sub
 
Top