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!

Visual Foxpro Combo Boxes 1

Status
Not open for further replies.

MelanieVA

Programmer
Mar 31, 1999
4
0
0
US
I am trying to allow my users to select a field value or enter a new field value with a combo box control. However, whenever I enter a new value instead of choosing an existing one, the value of the combo box is set to blanks. Any ideas?
 
I haven't been able to get this to work, either. Supposedly the combo box is set to blanks because it was an invalid value that was entered. You could put code in the "VALID" method to handle it, but the combo boxes definitely need to be improved.<br>
<br>
I also can't get the "BOUND COLUMN" to work right... it always seems to be bound to column 1, no matter what value is in bound column.
 
Combo Boxes are a real Pain - they have a mind of their own - I have found if I set the value to itself in valid method for adding values and in click method for selecting values that this solves problem for me.<br>
<br>
EG:<br>
If user enters a new value then in the valid method I have:<br>
<br>
STORE invalidchr(THIS.DISPLAYVALUE) TO THIS.VALUE, THIS.DISPLAYVALUE<br>
<br>
If user is just retrieving an existing value in the click I have similar code.<br>
<br>
<br>
where invalidchr removes non-visible controls <br>
************************************************************<br>
FUNCTION invalidchr<br>
************************************************************<br>
*++<br>
* Removes any asc values &lt; 32 from a char string<br>
*--<br>
LPARAMETER cstring<br>
LOCAL nchar<br>
IF LEN(cstring)&gt;0<br>
FOR nchar = 0 TO 31<br>
cstring = STRTRAN(cstring,CHR(nchar))<br>
IF LEN(cstring)=0<br>
EXIT<br>
ENDIF<br>
NEXT<br>
ENDIF<br>
RETURN cstring<br>
ENDFUNC<br>

 
If your combo box's list is based upon the contents of a table, you will need to update the table so that when the record is displayed later, the new choice will display. If updating the table is not ok, then you will need to handle building the combo box differently.<br>
<br>
i.e.:<br>
(Assume: 1) the combo box's control field is person.zip_code, and 2) the rowsource is either the zip_code table, or a cursor based upon the zip_code table)<br>
<br>
If combo.value &lt;&gt; combo.displayvalue then <br>
* value entered is not in the list<br>
Tmp = COMBO.DisplayValue<br>
INSERT INTO ZIP_CODES (ZipCode) VALUES (Tmp)<br>
COMBO.AddItem Tmp<br>
EndIf<br>
<br>
If you can't add the item to the table, then you have to add it to the combo list box when re-displaying the record:<br>
(In the form's init event)<br>
<br>
COMBO.AddItem person.zipcode<br>
<br>
The combo box will not display a value that is not in the list.<br>

 
Why don't you just create a combo list based on Values.<br>
<br>
1.Create a combo box the form<br>
2.Go to its data properties<br>
3.Give it a control source<br>
4.Set its RowSourceType to Value<br>
5.Now in the RowSource property type in the list you want to appear with each entry separated by a comma<br>
<br>
This will allow you to select from your list and also if a value is not in your list, you type it in and it will work.<br>
<br>
Hope this solves your problem.
 
Here is another scenario.
I have a combox whose controlsource is Genders(Gender_ID,Gender_Name).Now i want to be able to pick the Gender_Name on the combo,but the value Gender_ID be stored in another table say,EmployeeData.
Help me out!
 
Are you really wanting a combo box or just a list box? That is, do you want the user to input only things in your tables or to type in a new one? If the former, be sure to make the .style property = 2 (dropdown list)

At any rate, I'd use either SQL statement or alias (or maybe even Query) as the record source type and create a cursor with the proper things to be displayed. This way you don't have to go to a bunch of trouble to make things work. Personally I'd create a view with what you want and then use it as the alias type. Dave Dardinger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top