Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Populate combobox
Message
De
20/12/2001 20:38:48
 
 
À
20/12/2001 18:54:12
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00597089
Message ID:
00597111
Vues:
15
Hello Inge.

As Sergey already mentioned, you can put your SQL statement directly into the property sheet and use a RowSourceType of 3-SQL. However, I wanted to give you a little more info to help you understand what is going on here.

I'm going to answer your questions out of order because the answer will make more sense that way.

>> SELECT descr FROM myTable INTO ARRAY aArray
THISFORM.cmbBox.RowSourceType=5
THISFORM.cmbBox.RowSource='aArray'
USE IN _myTable

I'd like to put the above code in THISFORM.cmbBox.Init().
But cannot seem to work right. cmbBox comes up with empty list. <<

Your array aArray is scoped private by default (unless you exlicitly declare it as local in the init). So when the init finishes running, your variable goes out of scope and no longer exists. That is why your combo is empty.

What you need to do is create an array property of the form if you want the array to be seen by all the objects on the form. Even better, create a custom combo class and in the class designer, select class from the menu and then new property. Give the new property a name like aContents[1]. That way the combo and its RowSource are encapsulated inside the combo. You can then just set up the combo's RowSource as This.aContents and RowSourceType as 5 right in the property sheet. This code in the combo's Init:

SELECT descr FROM myTable INTO ARRAY This.aContents
This.Requery()

You need the requery() so that the combo updates its internal list when the contents of the underlying data source change.

>> What is the best practice to populate a combobox in a form class?
I had been using a SQL select statement into array: <<

It all depends on what you are trying to do <s>. I very often user RowSourceType 6-Fields when I want to move the recors pointer in an the underlying RowSource. I find type 3-SQL also very useful. I also know people who use nothing but RowSOurceType 5-Array or, like JimB, only use RowSourceType 0-None.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform