How to Use combo box in VC ++ 6.0

Source: Internet
Author: User

1. When you click the downward triangle of the control in the editing status, a height-adjustable figure is displayed. Raise the height. Otherwise, the drop-down list cannot be displayed during execution.

2. Add options for the combo box. In the editing status, select the properties of the combo box control, select the data tag, add options in the editing box, and press Ctrl-enter to add the next option.

3. Add a variable to the combo box
Combo box has two variables: ccombobox class variable and cstring variable.
The ccombobox variable is used to set the attributes of the combo box. It is generally used in the oninitdialog () function of the cdialog class. Add a variable in classwizard and select control in the category when adding the variable. For example, ccombobox. setcursel (0) is used to set the initial value of the drop-down menu. For details, refer to msdn.
The cstring variable is used to store the option values selected from the drop-down menu. Similarly, when the option changes, use the updatedata (true) function to update the value of the variable.

How to Use combo box controls in VC
1. How to add/delete combo box content
1. Add a row in the data label of the combo box control property, indicating a row in the combo box drop-down list. Press Ctrl + enter to wrap the text.
2. Dynamic addition during program Initialization
For example: // control content Initialization
Cstring strtemp;
(Ccombobox *) getdlgitem (idc_combo_cf)-> resetcontent (); // eliminate all existing content
For (INT I = 1; I <= 100; I ++)
{
Strtemp. Format ("% d", I );
(Ccombobox *) getdlgitem (idc_combo_cf)-> addstring (strtemp );
}
3. Add
For example, cstring strtemp;
Int icount = (ccombobox *) getdlgitem (idc_combo_cf)-> getcount (); // obtain the number of existing rows
If (icount <1) // prevents repeated addition
{
(Ccombobox *) getdlgitem (idc_combo_cf)-> resetcontent ();
For (INT I = 1; I <= 100; I ++)
{
Strtemp. Format ("% d", I );
(Ccombobox *) getdlgitem (idc_combo_cf)-> addstring (strtemp );
}
}
4. Delete
Deletestring (uint nindex) // delete a specified row,
5. Insert
Insertstring (INT nindex, lpctstr lpszitem) // insert the row to the specified position
6. Search
Findstring (INT nstartafter, lpctstr lpszitem) // you can find the specified character transfer position in all current rows. nstartafter indicates to start searching from that row.
Int selectstring (INT nstartafter, lpctstr lpszitem) // You can select a row that contains the specified string.
Ii. How to control the combo box drop-down Length

1. First, you need to know two points: 1. On the design page, click the drop-down arrow of the combo box. The box that appears is the drop-down box of the combo box.
2. There is a no integral height hook option in the attribute, indicating that the maximum length is the design length. If the actual content is longer than the design length, a scroll bar appears and the actual length is displayed if the content is smaller.

3. Select a line
1. Select:
Int IPOs = (ccombobox *) getdlgitem (idc_combo_cf)-> getcursel (); // the currently selected row.
2. Set
(Ccombobox *) getdlgitem (idc_combo_cf)-> setcursel (n) // you can specify the content of row N as the displayed content.

4. Get the combo box content
1. Retrieve the current content
(Ccombobox *) getdlgitem (idc_combo_cf)-> getwindowtext (strtemp );

2. Retrieve other row content
(Ccombobox *) getdlgitem (idc_combo_cf)-> getlbtext (n, strtemp );

Iv. Focus

You can use the getfocus () function to determine whether the control obtains the focus.

For example, if (getfocus () = getdlgitem (idc_edit_value2) // checks whether the focus is in the idc_edit_value2 edit box.

But the focus of ComboBox is different, because it is composed of edit and ListBox.

Therefore, getparent (): If (getfocus ()-> getparent () = getdlgitem (idc_combo_cf) is used to obtain the focus ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.