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

Combo problem 2

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
AU
I have a combo on a page of a pageframe. Its properties are set as RowSource = aMyarray and Rowsourcetype = 5.

The combo becomes enabled via a checkbox click.
I have a set step on in the click event

In the debugger I see the rowsource correctly as I step down the lines in the click() method.

I can also see all of the elements of the array in the debugger.

When they are all completed and back to the form the combo displays only the first item in the array.

I believe I have had this before but cannot remember the cure.

Can anyone help me?

 
What is the scope of the array (local, private, global)? Is it defined in the click method? Then it's gone the moment you end debugging.

Bye, Olaf.
 
Olaf has the correct diagnosis.

You should make the array a property of the form rather than declaring it PUBLIC or any other kludge to make it "always exist" while the form is running.

(Or, in a more encapsulated approach, make it a property of your combobox class. Each approach has pros and cons, and different implementation details.)
 
To give an example of what you can do:
ACOPY() can copy the array as a property of the form or the combobox, and then you set the combobox rowsource to "Thisfrom.aAyrray" or "This.aArray" instead of "aArray" only.

It's also possible to create an array property via object.AddProperty("aArray[10]") for example. This will stay as long as the object or form is running.

Using the form as the parent and holder of the array of course has the disadvantage, that more than one combo needing different arrays then need different array names, so dan has good advice in doing this on a combobox class you use instead of the native base combobox class.

Bye, Olaf.
 
Gendev,

In addition to the good advice that Olaf and Dan have given ...

You say you set RowSource = aMyarray. If you are doing this programmatically, you need to put aMyarry in quotes (you need to delimit it as a string).

That's because you set the RowSource to the name of the array, not the array itself. If you didn't do that, the RowSource would be the first element in the array.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Good observation, Mike.

But then in conjunction with Rowsourcetype array, I'd expect an error, as the value of the first array element is no array and as gendev describes he sees the first array item.

My guess is, that this is due to the displayvalue of the combo remaining at the first array item, while the array is already gone out of scope. But actually this is weird.

Further help could be given, when the code is shown, that is creating the array and the code, binding it to the combobox.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top