I have a combo box that have a list of values from 1 to 6. How can I set the default value to be 1?
Printable View
I have a combo box that have a list of values from 1 to 6. How can I set the default value to be 1?
Hi,
Use:
Regards,Code:myComboBox.SetCurSel(0); //0 based index of combobox
Laitinen
Code:CString strValue;
for (int i = 0; i < m_cmbValues.GetCount (); ++i)
{
m_cmbValues.GetLBText (i, strValue);
if (!strValue.CompareNoCase (_T("1")))
{
m_cmbValues.SetCurSel (i);
break;
}
}
Instead of searching for the text in the loop (as logan suggested) you could also use CComboBox::FindStringExact method
Well I assumed that the values was 1,2,3,4,5,6 in that order.
If not, do this;
EDIT: VIctor was faster, as usual :)Code:int itemToSelect = combo.FindStringExact(0,_T("3"));
combo.SetCurSel(itemToSelect);
Regards,
Laitinen
Uhhm, i would say: "... as an exception" :sick:Quote:
Originally Posted by laitinen