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

ComboBox not showing recorded item

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
508
Brasil
Hello colleagues!

In a ComboBox inside a Form I have 2 fields being shown fom a table named CIAS: SIGLACIA and NOMECIA, with a " - " (space separator space) between these two fields.

Well, I selected one option in the Combobox and it was recorded in another table (RESERVAS.DBF).

This is ok, my selection was recorded correctly.

But when I use a program to see the Form, my option selected in the ComboBox does not appear. It shows blank. Only if I click the down arrow in the ComboBox the items appear to select again.
CiaNotShown.jpgn CiaShown.jpg

What do I have to do in order for my selection to appear in the ComboBox?
 
Last edited:
As a rule of thumb, the dropdown will only select something if the value in the table matches one exact value in the list. If it doesn't match anything exactly, nothing will be selected. Technically, there can be more than one match, but it will use the first one it finds.

If you can select the item from the list, and it DOES update the table, then it's definitely bound correctly to the column, but perhaps its just a timing problem, where you just need to refresh the control after defining the control source. If you want to test this, save the record while it's still showing the blank, and see if it saves a blank value in the table. If it displays the correct value in the table, that's proof that it held the correct value, but it wasn't refreshed.
 
You must set the value of drop down in Init Event of form from the database in the similarly way you have set the record source.
So init invent you should have code as
combobox.Value = Value from Record of data base and you will have to update the value every time record changes.
 
The combobox item can be determined by a controlsource, but you can't make a controlsource be two fields. And if you make the controlsource an expression you'd disable the feature of a controlsoure to write the value into the controlsource as you can't write to an expression, you can only write to a single field.

As you say you get a recorded vcalue in a separate table reservas.dbf, there must be a controlsource set to a fieild of reservas.dbf. If that's empty at the beginning of the form, the combobox value of course isn't set.

The usual way of working is again by a principle you don't implement in all your data design: primary/foreign key. As you don't have those, you'll never have a straight forward way of setting up a combobox to maintain some field of a table with one of the options. I don't see how you can make the combobox display the item automatically in this situation, but I also don't have a full understanding by what you posted, about which fields of which tables are invovled in this.

The item list displays CIAS.SIGLACIA + " - " + CIAS.NOMECIA and the item picked is stored into which field of RESERVAS.DBF?
 
Last edited:
Well, the data is correctly recorded in the table:
CiaGravada.jpg

In the next day, when I run the Form, it should show my selected item the day before, but it shows only if I click on the down arrow key in the ComboBox. I have this code in the Init of the Form:

Code:
WITH thisform
    ....
    .cboCia.Value         =YSIGLACIA + " - " + YNOMECIA
    ...
YSIGLACIA and YNOMECIA are read (confirmed, their values are in memory) from table RESERVAS.DBF (YSIGLACIA=SIGLACIA, YNOMECIA=NOMECIA, etc in a procedure to put data from the table RESERVAS.DBF into memory variables)
 
Well, a combobox can't feed 2 fields with its controlsource and the controlsource is the only way to make a combobox pick an item automatically.

What do you set in the cboCia controlsource? Nothing? Then you can't expect the item to be picked automatically.

You set the value and expect this to pick the item. It does, but to see it do the standard thing you do in such cases: THISFORM.REFRESH().

Picking an item from a combobox sets the value and the display is the picked item, because you pick it.
Setting the value does position on the item, but doesn't cause the form or the combobox to refresh, so do it.

Use a combobox with the right databse design and controlsource and all of that is automatic in both directions.
 
Last edited:
Chris:
THISFORM.REFRESH() in the Form, Init, after setting the values for each object doesn't updated the ComboBox when calling the Form after data have been recorded. The table has the correct data recorded, but when I call the Form again to verify its data, all other objects show their data, except the ComboBox.

The contents of the ComboBox come from 2 fields from RESERVAS.DBF table: SIGLACIA and NOMECIA.

The ControlSource property of the ComboBox is (None).
 
You have to do THISFORM.REFRESH right after you set the value, not just once in form init. Everytime you change the value programmatically you also do THISFORM.REFRESH.
 
Last edited:
The ComboBox is populated with CIAS.DBF table (the ComboBox presents SIGLACIA - NOMECIA items)
After the user made a selection in the ComboBox, that selection is recorded in the file RESERVAS.DBF, in its fields SIGLACIA and NOMECIA.

That said, when the user enter the Form, eventually to change some data in it, the RESERVAS.DBF is read and the data from fields SIGLACIA and NOMECIA are copied to memory variables YSIGLACIA and YNOMECIA, respectivelly. I need to show the item originally selected, but it shows blank.

Then if the ComboBox GotFocus, all the options appear and the user can change the original selection.
 
'Are we back to square oine, now?

You can only expect the setting of the combobox value to have an effect after the combobox items are populated. If you only poppulate the combobox in it's gotfocus, then doing things before the combobox has its items has no effects. This is simple reasoning of cause and effect. That's pure logic and hasn't even got to do anything with FoxPro.
 
Chris Miller: You can only expect the setting of the combobox value to have an effect after the combobox items are populated.

So, I populated the ComboBox in the Form, Init property. Then, it worked!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top