mfc中怎么使组合框可编辑
mfc中如何使组合框可编辑?
组合框关联了一个变量,想把该变量里的内容赋给组合框里,显示在组合框里,但是不能实现,怎么解决,求指教?
------解决方案--------------------
CComboBox::AddString()/InsertString()
------解决方案--------------------
"组合框关联了一个变量"
组合框应该关联成控件。(control)
------解决方案--------------------
楼主要学会查询MSDN
CComboBox::AddString
int AddString( LPCTSTR lpszString );
Return Value
If the return value is greater than or equal to 0, it is the zero-based index to the string in the list box. The return value is CB_ERR if an error occurs; the return value is CB_ERRSPACE if insufficient space is available to store the new string.
Parameters
lpszString
Points to the null-terminated string that is to be added.
Remarks
Adds a string to the list box of a combo box. If the list box was not created with the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted.
To insert a string into a specific location within the list, use the InsertString member function.
组合框关联了一个变量,想把该变量里的内容赋给组合框里,显示在组合框里,但是不能实现,怎么解决,求指教?
------解决方案--------------------
CComboBox::AddString()/InsertString()
------解决方案--------------------
"组合框关联了一个变量"
组合框应该关联成控件。(control)
------解决方案--------------------
楼主要学会查询MSDN
CComboBox::AddString
int AddString( LPCTSTR lpszString );
Return Value
If the return value is greater than or equal to 0, it is the zero-based index to the string in the list box. The return value is CB_ERR if an error occurs; the return value is CB_ERRSPACE if insufficient space is available to store the new string.
Parameters
lpszString
Points to the null-terminated string that is to be added.
Remarks
Adds a string to the list box of a combo box. If the list box was not created with the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted.
To insert a string into a specific location within the list, use the InsertString member function.
- C/C++ code
// The pointer to my combo box. extern CComboBox* pmyComboBox; // Add 20 items to the combo box. CString str; for (int i=0;i < 20;i++) { str.Format(_T("item string %d"), i); pmyComboBox->AddString( str ); }
------解决方案--------------------
m_combo1.AddString("A1");
m_combo1.AddString("A2");
m_combo1.InsertString(1,"B1");
m_combo1.InsertString(2,"B2");
------解决方案--------------------
m_combo.SetWindowText("");
------解决方案--------------------
如果有两条
m_combo.DeleteString(1);
m_combo.DeleteString(0);
------解决方案--------------------
CComboBox::ResetContent
或者
for (int i=0;i < pmyComboBox->GetCount();i++)
{
pmyComboBox->DeleteString( i );
}
都行
------解决方案--------------------
组合框关联的变量,这个变量保存的是选择的索引。