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!

Disabling ListBox Items 1

Status
Not open for further replies.

AllanB1

Programmer
Dec 30, 2002
201
US
While there are list box properties with which to display the foreground and background colors of the disabled items themselves contained in a list box, namely:

Control.DisabledItemBackColor
&
Control.DisabledItemForeColor

...just how you go about disabling the items (not the entire list box) is not so obvious. Can anyone help?

Thank you all!
 
Hi

You can disable an item in a listbox by prefacing the expression with a single backslash ("\")

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
Happy New Year [bigears] [party] [2thumbsup]

 
Thank you. While the backslash is used for this purpose in menu functions, I never considered it for listbox items.

Also, it looks like the application event code (ie., dblclick) needs to take care of rendering the item disabled, since the backslash seems to merely change the fore & back colors and not really cause the item to be inaccessible.
 
AllenB1

I don't seem to get the same results as you. When I disable an item in a list box and I doubleClick on it the doubleClick event does not trigger, Copy the following in a program and run it:
Code:
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	ADD OBJECT list1 AS listbox WITH ;
		RowSourceType = 1, ;
		RowSource = "Hello,\Hola,Bonjour", ;
		Height = 193, ;
		Left = 60, ;
		Top = 24, ;
		Width = 229, ;
		RightToLeft = .T., ;
		Name = "List1"
	PROCEDURE list1.Click
	ENDPROC
	PROCEDURE list1.DblClick
		MESSAGEBOX(this.Value)
	ENDPROC
ENDDEFINE
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike:

I'm not sure what changed between the time I first tried it and after I read your response, but my application works as you stated.

Mine is a very common application - the user double-clicks an item in one listbox to populate another. The first time, I was able pick the same item multiple times even though the item was grayed out. After I read read your response, I tried it again and it worked as you said - dblclick, rtclick, etc. don't fire on the disabled items.

Must be the power of suggestion...

Thanks again ramani & Mike.
 
Mike:

I just noticed a little twist that caused me to say the list items weren't really being disabled. After items are in fact disabled, when the listbox loses and then regains focus, the items are once again enabled. They shouldn't be, however, since I'm prefacing each item to be disabled with a backslash and that's not being changed. Try it.

Thanks again.

Al
 
AllenB1

I just noticed a little twist that caused me to say the list items weren't really being disabled. After items are in fact disabled, when the listbox loses and then regains focus, the items are once again enabled. They shouldn't be, however, since I'm prefacing each item to be disabled with a backslash and that's not being changed. Try it.

I cannot seem to be able to duplicate your situation. How is your list created? SQL? It may require a requery in the gotFocus event of the list.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike:

I had created its form over a year ago and it's been in use in its parent application ever since. I forgot and didn't even consider the listbox's rowsourcetype is 2 (alias).

It's being systemically requeried when it loses and regains focus, so the disabled items obviously abandon the preceding backslash, causing them to be enabled.

Thanks for leading me to this conclusion in your SQL suggestion.

Al
 
AlanB1

It's being systemically requeried when it loses and regains focus, so the disabled items obviously abandon the preceding backslash, causing them to be enabled.

This might be a design issue, but I always found that presenting a user with a choice that is not available to him, only tends to frustrate the user more then anything else. Have you consider NOT showing the "disabled" items in your list?
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 

We're on the same page, Mike. As I said before, users select items to populate another listbox. I never before disabled the items in the originating listbox, but instead prevented the items from being duplicated into the second, through coding.

Using or not using the listbox item disabling function ("\") is not all a big problem; I merely looked at my application in a different light recently, since I had never used the "\" for listbox items before. I am in fact surprised I have missed this in all my years using VFP.

I will likely revert my code to what it was for over the past year.

You've been a big help and thank you and ramani for your professionalism.

Al
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top