La boîte à options est un objet qui permet à l'utilisateur de sélectionner une valeur parmi une liste
en entrant des caractères dans une zone de saisie ou en sélectionnant directement la valeur dans la liste.
Pour utiliser un tableau au lieu d'un fichier, voir dans l'exemple : Lire un fichier DBF
Exemple de Combobox.
Télécharger le fichier PAYS.DBF
*
* ClasseCombobox.wfm - Test classe ComboBox.
* ------------------------------------------
*
PRIVATE oDbf
LOCAL f
*
oDbf = new QUERY()
oDbf.sql := 'select * from "PAYS.DBF"'
*
f=NEW Showbox()
f.ReadModal()
*
MSGBOX(f.Cb1.value) && Retour du pays sélectionné.
*
f := null
oDbf := null
*
RETURN
*
CLASS Showbox OF FORM
with (this)
Mdi := .F.
height := 10
left := 30
onOpen := class::Form_onOpen
top := 5
width := 45
text := "Test Combobox"
onGotFocus := {;form.Cb1.setFocus()}
endwith
*
this.Txt1 = new TEXT(this)
with (this.Txt1)
Text := "Choisissez le pays"
FontBold := .T.
Width := 40
Top := 1
Left := 3
endwith
*
this.Cb1 = new COMBOBOX(this)
with (this.Cb1)
FontBold := .T.
Top := 4
Left := 1
Width := 38
Style := 2
endwith
*
this.Pb1 = new PUSHBUTTON(this)
with (this.Pb1)
onClick := class::Pb1_OnClick
height := 1
left := 1
top := 8
width := 12
text := "Choisir"
endwith
*
* -----------------------------------------------------------------------------
FUNCTION Form_OnOpen
* -----------------------------------------------------------------------------
*
oDbf.active := .T.
oDbf.rowset.live := .F. && Ne pas modifier le fichier.
*
form.Cb1.DataSource := oDbf.rowset.fields["CO"]
*
* Sélection du pays existant.
*
oDbf.rowset.locateOptions := 0 && Set Exact on et respecte la casse.
oDbf.rowset.applyLocate("PY = '" + "FR" + "'")
form.Cb1.value := oDbf.rowset.fields["CO"].value
*
oDbf.active := .F.
*
RETURN
*
* -----------------------------------------------------------------------------
FUNCTION Pb1_OnClick
* -----------------------------------------------------------------------------
*
oDbf.active := .T.
oDbf.rowset.live := .F. && Ne pas modifier le fichier.
*
oDbf.rowset.locateOptions := 0 && Set Exact on et respecte la casse.
oDbf.rowset.applyLocate("CO = '" + form.Cb1.value + "'")
*
oDbf.active := .F.
*
form.close()
*
RETURN
*
ENDCLASS