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

How to cancel a selected item from a combo box

Status
Not open for further replies.

nwb1

Programmer
Apr 28, 2004
39
GB
Hi,
In my VFP form, I have a combobox control which display list of products. Some products can only be selected depending on the answer to previous question.
Is there a way to control what user can select in a combobox?

I can track the new value selected in Interactivechange method, but not sure how to cancel the selection. I have tried following without success.
Any help on this greatly appreciated.

Combobox InteractiveChange:

if Left(thisform.txtName.value,2)="HZ" or ;
Left(thisform.txtName.value,2)="HX"
cancel =.t.
Endif

 
In the List that supplies the combobox, you can preceed any choice with "\" to disable it... this doesn't work too well if the RowSource is anything you care about (since you're changing the original data), so I usually use an array RowSourceType or a Value RowSourceType.

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Many thanks for the info.

Is there a way to cancel the user selected item without disableing items from the list?

I can give them a warning, but if they select yes (i.e to a messagebox with warning), is there a way to reverse the item to its original value?
 
nwb1;

Move your code from the InteractiveChange event to the When event and change cancel=.t. to RETURN .F.

This will prevent the combo box from being selected

Ed

Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
With above coding users can not select an item. Warning should only show for some items and its depending on the selected item value. Is there a way to give user to select the item first, then check the value, and show a warning?
Thanks again.
 
In the InteractiveChange event:

IF [condition]
Message [Do you really want to select this one?]
IF [yes]
RETURN && leave selection as is
ELSE
THIS.Listindex = 0 && "cancels" selection
ENDIF
ENDIF


Jim
 
Thanks for that. It works.
However is there a way to default it to its original value (if user select NO) without setting it to blank?
 
Capture the Listindex value in the When event. Reset to that value instead of 0.

Jim
 
Thanks. I guess I have to use a public variable to store the list index value?
 
No, just create a new form property and store it there.

In the When event:

THISFORM.mynewproperty = THIS.Listindex

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top