In VC + + program design, combobox control is more common form element control, and for beginners, master the various usages of ComboBox is particularly important, this article will summarize some practical ComboBox control usage, for everyone's reference.
Add/Remove combo box content:
1. It is generally added in the Data tab of the ComboBox control properties, one line representing a row in the ComboBox Drop-down list, and CTRL + ENTER for the newline.
2. Dynamically add when the program is initialized, such as: the content of the control is initialized:
CString strtemp;
((ccombobox*) GetDlgItem (IDC_COMBO_CF))->resetcontent ();//Clear existing content for
(int i=1;i<=100;i++)
{
Strtemp.format ("%d", I);
((ccombobox*) GetDlgItem (IDC_COMBO_CF))->addstring (strtemp);
}
3. Add content items at drop time, such as: CString strtemp;
int icount= ((ccombobox*) GetDlgItem (IDC_COMBO_CF))->getcount ();//Get existing number of rows
if (icount<1)//Prevent repeated additions
{ (
(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 content, that's easier, just one line:
DeleteString (UINT nindex)
5. Insert the content item, also quite simple, the row is done: Inserts the row to the specified position
insertstring (int nindex, LPCTSTR lpszitem)
6. Find and divide the situation so that:
findstring (int nstartafter, LPCTSTR lpszitem)//can find the position of the specified character in all of the current rows, and Nstartafter indicate that the search starts from that line.
int selectstring (int nstartafter, LPCTSTR lpszitem)//can select the line containing the specified string
Second, control the ComboBox of the dropdown box length:
First you need to know two points:
One is that in the design interface, click on the combo box Drop-down arrow, at this time the adjustment box appears combo box's drop-down adjustment boxes.
The second is the attribute has a No integral height hook option, which indicates that the maximum length is the design length, if the actual content is more than the design length, the scroll bar appears, less on the actual length of the display.
Third, select a row
1. Check:
int ipos= ((ccombobox*) GetDlgItem (IDC_COMBO_CF))->getcursel ();//currently selected row
2. Set:
((ccombobox*) GetDlgItem (IDC_COMBO_CF))->setcursel (n)/Set the contents of the nth row as displayed
Iv. acquisition of ComboBox content:
1. Get ComboBox Current content:
((ccombobox*) GetDlgItem (IDC_COMBO_CF))->getwindowtext (strtemp);
2. Get Other line content:
((ccombobox*) GetDlgItem (IDC_COMBO_CF))->getlbtext (n,strtemp);
V. Get the Focus:
You can use the GetFocus () function. For example:
if (GetFocus () ==getdlgitem (idc_edit_value2))//Determines whether the focus is within the edit box idc_edit_value2.
But ComboBox's focus is different because it's made up of both edit and ListBox. So get the focus to use GetParent ():
if ((GetFocus ()->getparent ()) ==getdlgitem (IDC_COMBO_CF))
I hope the combobox control usage mentioned in this article can help us to learn VC + +.