Combo box Control (ComboBox) is also a commonly used control in VFP, the combo box has the function of text box and list box, its name probably also comes from this. The common properties and methods of the combo box are given in detail in the basic course of VFP-the combo box control (ComboBox).
In the application of the combo box control, a very important link is its RowSourceType and rowsource combination of these two attributes. For example, looking at the example of VFP: Locating and locating records in a table This example is to set the RowSourceType property value of the combo box to the "N" Value, And in looking at the example of VFP: Remove duplicate records in query results This example is to set the RowSourceType property value of the combo box to "2-alias".
This control has a style property, and if you set this property to "0-drop combo box", you can use a Drop-down list box while using a text box that is grouped in it, which is also the default property value of the system; If you set this property to 2-drop-down list box, the combo box has only the function of a list box If you want the combo box to have a selected value automatically when the form starts, you can assign the selected value to the Displayvalue property of the combo box in the form's Init event.
The control also has a property worth mentioning: text, which we can use to enter the value in the text box in the combo box, or assign the value to a variable. This property is important, such as having to add a value entered into a text box to a list item in a combo box at the same time.
About adding list items to a combo box: MSDN Help gives you a good idea to check for duplicate values in the Drop-down list of the combo box before adding it, and give a sample code that occurs in the valid event of the combo box. The examples given later in this article refer to this part of MSDN's code in the code for adding the list item, but this example puts the action in the Click event of the command button.
This article designs an example of a combo box that can select values and enter values. In the case of VFP: the use of a hyperlink control in one example we can access only a few sites in the list box, this article uses the combo box control to improve the example so that it can not only access the default URL, You can also access a URL by entering a value in the text box of the combo box, and the URL is automatically added to the Drop-down list of the combo box after the visit, running the following image:
The production steps are as follows:
Create a new form, set its Caption property to programming Getting Started network-combo box control, and save it as "form 1.scx".
Add a Label control to the form and set its Caption property value to "Please enter or select a URL."
Add a command button control Command1 to the form and set its Caption property value to "go!".
Add a combo box control Combo1 to the form, set its RowSourceType property value to "N", and the Style property value with the default of "0-drop combo box".
The size and position of each control and form are adjusted according to the above figure.
Vi. Add event code:
1, the form of the Init event code:
This. AddObject ("Hyperlink1", "HyperLink") && Add Hyperlink control
This.combo1.additem ("Baidu")
This.combo1.additem ("Google")
This.combo1.additem ("Sogou")
This.combo1.additem ("Yahoo")
This.combo1.additem ("MSDN")
This.combo1.additem ("CSDN")
This.combo1.additem ("Yesky")
This.combo1.additem ("Little Bird")
2, the command button click event Code:
Str1=alltrim (thisform.combo1.displayvalue) do case str1 case str1= "Baidu" && visit Baidu Thisform. Hyperlink1.navigateto ("www.baidu.com") Case str1= "Google" && visit Google thisform. Hyperlink1.navigateto ("www.google.cn") Case str1= "Sogou" && visit Sogou thisform. Hyperlink1.navigateto ("www.sogou.com") case str1= "Yahoo" && visit Yahoo Thisform. Hyperlink1.navigateto ("one.cn.yahoo.com") Case str1= "MSDN" && access to Microsoft MSDN Home page thisform. Hyperlink1.navigateto ("msdn.microsoft.com") Case str1= "CSDN" && access CSDN website thisform. Hyperlink1.navigateto ("www.csdn.net") Case str1= "Yesky" && access Pole thisform. Hyperlink1.navigateto ("www.yesky.com") case str1= "Little Birdie" && access programming Gateway Thisform. Hyperlink1.navigateto ("www.bianceng.cn") otherwise if empty (Alltrim (Thisform.combo1.text)) MessageBox ( "Please enter or select a URL!" ") Thisform.combo1.setfocus return endif thisform. HyperlInk1. NavigateTo (Thisform.combo1.text) litemexists=.f.
&& Suppose the value is not in the list. For I=1 to THISform.combo1.ListCount IF THISform.combo1.List (i) =thisform.combo1.text liteme Xists=. T. EXIT ENDIF endfor IF!litemexists THISform.combo1.AddItem (THISform.combo1.Text) ENDIF endcase
Seven, run "form 1.scx".
This example code is debugged in the win2003+vfp6.0 environment.
See the full set of "rookie also learn VFP" tutorial