Link to home
Start Free TrialLog in
Avatar of MattAllen
MattAllen

asked on

Disable options in a list box!!

Hey experts,

I have a list box with a series of options but i want to be able to disable some of these options as they are not available, hence stopping the user selecting this option...how do i do this!

Thanks in advance people
Matt
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fds_fatboy
fds_fatboy

You might be able to use a listview instead of a listbox. You can simulate disabling an item by changing its forecolor property, then catching it in the itemcheck event handler.

Here is an example.

Open a New VB Standard Exe Application. In Form1 add a listview control (ListView1) and add the following code to Form1:

Option Explicit

Private Sub Form_Load()
    Dim i As Long
   
    ListView1.View = lvwList
    ListView1.Checkboxes = True
    ListView1.LabelEdit = lvwManual

    For i = 0 To 19
        ListView1.ListItems.Add , , "Item " & i
    Next
   
    ListView1.ListItems(3).ForeColor = vbGrayText 'Disable an item
End Sub

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    If Item.ForeColor = vbGrayText Then 'If disabled...
        Item.Checked = False            '... Reset checkbox
    End If
End Sub
Avatar of MattAllen

ASKER

Cheers fellas,

i needed a msgbox to come up ideally to tell the user becasue it is only a demo version of the software but thanks a lot guys

Matt