Link to home
Start Free TrialLog in
Avatar of terrypba1
terrypba1

asked on

VFP9 ComboBox only showing first item in array

A combobox control I am adding to a Visual Foxpro 9 form shows only the first item in the list.
I am creating a two column array from a table, and the debugger shows all rows are created.
If the record in main table in the form is tied to that first item, the item shows up in the control.
If not, the control is blank.
I can drop down the list, pick the one item, and it will now be tied to the main table in the save procedure, and appear in the combo box if I call up that record again.
So the create array procedures and save procedures seem to be working, but I am only seeing the first record in the array on the form. .
I have used this combobox class for many years, although not recently.

RoWSource is 'this.aitems' which seems to be created properly.
RowSourceType is 5-Array

Any thoughts?
Avatar of Olaf Doschke
Olaf Doschke
Flag of Germany image

What are other properties of the combobox, columncount, columnwidhts, etc.?

What is ALEN(this.aitems,1)?

Bye, Olaf.
This is hard to answer without access to your code so I may offer some guesses only...

The first thing you should check is the Combo property named DisplayCount.

Even when you are sure the array has 5 rows then you may display the array size in WAIT WINDOW command in e.g. GotFocus method code of the combo.

 Additionally you may click into the combo at run-time, then press F4 and down or up arrow. Does it show other combo options?
Avatar of terrypba1
terrypba1

ASKER

I am stealing a working box from earlier forms that had DisplayCount set to 0 and works as expected. If I change it to 5 I still get a blank box, or the first item, if I have selected that item previously. (All records in the main table have valid data for this field.) It is behaving exactly as if there is only one record in the array.
The code to create the array is called in the init of the combobox.
SELECT cadd_desc, iadd_id FROM inv_add INTO ARRAY this.aitems ORDER BY cadd_desc
The debugger shows the array created correctly.
I can run the code from the command window as
SELECT cadd_desc, iadd_id FROM inv_add INTO ARRAY aitems ORDER BY cadd_desc
and get the correct array
But the dropdown only shows 1 option, using F4 and arrows.
Are you sure you set RecordSource to "This.aitems" and not to This.aItems?
Abd: When do you execute this query? Grid.Init()?

Bye, Olaf.
Alen(this.aitems,1) is 13.
Always worth checking. This is from a class I've used for years, so I don't touch much of the basics. RecordSource is definitely this.aitems.
The array is created in the Init of the ComboBox.
I can select the one record that does show, and save it for the main record, so the connections are working.
Notice the difference in what I wrote: "This.aItems" vs This.aItems. If you have code setting Thiis.RecordSource = This.aItems you effectively set the recordsource to the VALUE of This.aItems[1] and not to the array.

Also, asked once more: When do you execute the query?
Please place the following code to the Combo's GotFocus method code and tell us what you see:

WAIT WINDOW TRANSFORM(Alen(this.aitems,1) ) + "/" + TRANSFORM(this.DisplayCount) TIME 1

If it shows correct values then you may try additional hints, e.g.
Place the following code to the Init method of the Combo (and comment out the original code)
THIS.AddProperty('aOptionsX[1,1]', .F.)

WITH THIS
  DIMENSION .aOptionsX[5,2]
  .aOptionsX[1,1] = 10
  .aOptionsX[1,2] = "text1"
  .aOptionsX[2,1] = 20
  .aOptionsX[2,2] = "text2"
  .aOptionsX[3,1] = 30
  .aOptionsX[3,2] = "text3"
  .aOptionsX[4,1] = 40
  .aOptionsX[4,2] = "text4"
  .aOptionsX[5,1] = 50
  .aOptionsX[5,2] = "text5"
ENDWITH

THIS.RowSource = 'THIS.aOptionsX'

RETURN DODEFAULT()

Open in new window

and check the form behavior.  (The DODEFAULT() call is important and I also expect the RowSourceType = 5)
Thanks Olaf. The record source is set to this.aitems, with no quotes. Works in all my other forms. The array is created in a "Setup" method called by the init of the combobox class. Again standard in all my forms.
pcelba, the window gives me 13/0. The default DisplayCount is 0 and it  works in all other  forms where I use this class. If I change it to, say, 5, result is the same: list has one item.
 RowSource Type is 5.
I'll try forcing the array with the code you suggest when I get a chance.
ASKER CERTIFIED SOLUTION
Avatar of Olaf Doschke
Olaf Doschke
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fraid I'm too old-fashioned to have used Try...Catch! think I used it in some later code, but not hiding any errors here.
aItems[1,0] is set for .F. as a property of my Combo class.
But Requery in the form init worked!
Many thanks Olaf and pcelba, as always!
LOL, I've had the REQUERY() in the code posted above but I've supposed the class has it inside and DODEFAULT() will fire it so it was removed...
Life and Foxpro can be strange at times!