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

Manually input value into combo box?

Status
Not open for further replies.

shelbytll

Programmer
Joined
Dec 7, 2001
Messages
135
Location
SG
for a combo box, i have a list of items for user to select.
Is it possible that if the item that the user want is not in the list, directly type it into the combo box?

I tried it myself, however, the value that i manually type in is not being captured. Only when I select the item from the list then it's being captured. I wonder is there any way to do that? I am a clever newbie...[peace]
 
shelbytll

Set the combobox .Style = 0, and .BoundTo = .F.

Then use the combobox .Value property HTH

Chris [pc2]
 
ChrisRChamberlain ,
I did what u said.
BoundTo:false
Style:0
Value: (I key in something)

but still didn't work I am a clever newbie...[peace]
 
shelbytll

In the .Valid() event of the combobox put :-

THISFORM.property = THIS.Value

or

myvariable = THIS.Value

or

REPL TABLE.filedname WITH THIS.Value

As the combobox loses focus, the property, variable or field will be updated with the combobox value. HTH

Chris [pc2]
 
Hi ChrisRChamberlain,
I added THISFORM.property = THIS.Value to the Valid event of the comboxbox already but when run, it gave me an error of property PROPERTY is not found. I am a clever newbie...[peace]
 
Hi,
in the Valid Procedure, I code:
If !Empty(This.DisplayValue)
? This.DisplayValue
ENDIF

when i run the form, i manually enter values into the combo box and upon click on the submit button, it did appear the value, however, it still prompt me to enter a value. BTW, my validation code for in the click event of the button is:

if empty(thisform.brand.value) then
  messagebox ("Brand:" + chr(13) + chr(10) + "Simply type a new brand if it doesn't exist" + chr(13) + chr(10) + "Otherwise select a brand from the list")
  return
endif

Maybe i need to code something else in the click event? I am a clever newbie...[peace]
 
shelbytll

THISFORM.property = THIS.Value

This is an example of how you can assign the value of a control to a form's property - it enables you to use the property as a variable which is accessible not only within the form, but from elsewhere providing the form has an object reference.

You have an error because .Property does not exist. You add a property by clicking on Form > New Property... and filling in the dialog with the name of the property you wish to add.

If you want to force the user to either select a value from the combobox or enter a value into the combobox, in the .Valid() event, put :-

IF EMPTY(THIS.Value)
[tab]MESSAGEBOX([Your message, etc])
[tab]RETURN .F.
ENDI

This means you could dispense with your code in the command button. HTH

Chris [pc2]
 
Hi,
ermmm... still can't seem to get it..

I added a property to the form, property name is property. Never set the method etc.

Then in the .Valid() of the combo box, I code THISFORM.property = THIS.Value.

But still when click on button, still got prompted. Is there something I miss out?

Thanks for your paitence I am a clever newbie...[peace]
 
Hi,

I found an alternative to it.
In the click event of button, I code:

b = thisform.brand.value
if empty(b) then
   b=THISFORM.brand.displayvalue
endif


and that solve my problem... Thanks... I am a clever newbie...[peace]
 
Just a quick comment.....

The easiest way to tell if something that is typed into a combobox is a new value is to compare this.value to this.displayvalue. If they are not the same, then the displayvalue is a new item, not in the original source..doesn't matter what the source is...alias or array. If you want this new item to become part of the list, then manipulate your source and add the new this.displayvalue to it.

hth,

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top