Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

P.S. "to Disable items in listbox. . . ."

Status
Not open for further replies.

NewToProgramming

Technical User
Jun 24, 2003
31
0
0
US
Here is a little sample of the code I have tried so far to get it to work:
Please let me know what I am doing wrong. Make sure you have read my previous thread regarding what I am trying to do.


Private Sub lstDisposition_Click()
With Me
If lstDisposition.Selected(0) = True Then
lstDisposition.Enabled(1) = False
lstDisposition.Enabled(2) = False
lstDisposition.Enabled(3) = False
lstDisposition.Enabled(4) = False
Else
lstDisposition.Enabled(1) = True
lstDisposition.Enabled(2) = True
lstDisposition.Enabled(3) = True
lstDisposition.Enabled(4) = True
End If
End With
End Sub
 
As far as I can tell you can't disable particular items, it's either the the list box or nothing. You may want to try unselecting items that are not compatible.

If lstDisposition.Selected(0) = True Then
lstDisposition.Selected(1) = False
...
Else
...
End If

Or you may want to try a control array of Check Boxes and enable or disable them.
 
Thanks. I will try the first. And then maybe I'll try doing a control array of Check Boxes too. Not sure I know how to do that. I have not worked with arrays before. Would I just make each separate option a Checkbox and then do something similar to the code I wrote above?
 
Just in case anybody is new to this thread, this was the original thread I posted on this question:



I have created a listbox with the multiselect property set to True. My
listbox has 5 items. I want to create logic in my program so that if,
for example, the user selects the first item on the list (ListIndex = 0),
they are not able to select any other item on the list. If, instead of
selecting the first item on the list, they selected the second item
(ListIndex = 1) I want to make it so that if they pick the second item
they can also select items 4 and 5, but not 1 or 3. And the program
would continue on so that depending on what item(s) they click, it
would automatically disable other items on the list that are not
compatible, only allowing them to select the multiple list items that
ARE compatible. Any help would be much appreciated. Thanks.
 
To make a control array of check boxes.
1)drop a check box on the screen.
2)select the check box.
3)hit ctrl-c to copy the check box.
4)select the form that you want the check box to appear on.(or if you were putting them on a frame you would need to select the frame)
5)hit ctrl-v to paste the control.

The first time you do this you will be asked if you're sure you want to make a control array. Click yes. Then repeat these steps for as many check boxes that you want.

You can then enable or disable them.
chkBox(0).Enable = True
chkBox(1).Enable = False
...
 
Thanks. I am trying to do your instructions, but when I past the checkbox it does not ask me if I want to make a control array. I am using the Visual Basic that is a part of Microsoft Word. Would this make a difference?
 
Sorry i'm not familiar with the word version. Maybe somebody else can answer that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top