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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grey out item in combo box

Status
Not open for further replies.

mark1110

Programmer
Apr 20, 2005
85
US
Hi,

I am not sure if this could be done, but if I have a combo box using VB6 and I am adding items to it i.e.

myCombo.Clear
myCombo.AddItem("Green")
myCombo.AddItem("Red")
myCombo.AddItem("Blue")
myCombo.AddItem("Pink")
myCombo.AddItem("Purple")
myCombo.AddItem("White")
myCombo.AddItem("Yellow")

Is there a way when the user clicks on the combo box to have Red, White, and Yellow be greyed out so the user can't select it?


Mark
 
I don't think you can do that with a standard combo box. I use one called SBCombo which allows you to change the colours of the list items but it still wouldn't prevent you from choosing them.

Perhaps you could use a popup menu instead of a combo box - that way you could place a Tick next to the selected colour and also grey out the other colours. You would then display the chosen colour in a Label or TextBox which the user could click to access the popup menu.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
A standard combo does not allow change of colors. As mentioned there are other controls to do this. You could do it with a list view. With most controls you can "fake" locking it.

After the user chooses Red, White, or Yellow have it roll back to the previous value. It will appear as if it is locked since they can not change the value. Some controls have a before update event allowing you to cancel the event.

If I was using a standard combo I would on your event change the text for the locked fields so they show like

(Locked) Red
(Locked) White
or something like that

Public Sub changeToLocked()
myCombo.RemoveItem 1 'red
myCombo.AddItem "(Locked) Red", 1
myCombo.RemoveItem 5 'White
myCombo.AddItem "(Locked) White", 5
myCombo.RemoveItem 6 'Yellow
myCombo.AddItem "(Locked) Yellow", 6
End Sub

Then make a similar unlock event.
then to fake locking

Public oldValue As Variant

Private Sub MyCombo_Change()
If Left(myCombo, 8) = "(Locked)" Then
MsgBox "White, yellow, Red are Locked"
myCombo.Value = oldValue
End If
oldValue = myCombo.Value
End Sub

Not the greatest effect, but best works ok.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top