-
April 13th, 2007, 06:11 AM
#1
Set default value for Combo Box
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?
-
April 13th, 2007, 06:21 AM
#2
Re: Set default value for Combo Box
Hi,
Use:
Code:
myComboBox.SetCurSel(0); //0 based index of combobox
Regards,
Laitinen
-
April 13th, 2007, 06:28 AM
#3
Re: Set default value for Combo Box
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;
}
}
"I rather not play football than wear Nerrazzuri shirt" - Paolo Maldini
FORZA MILAN!!!
-
April 13th, 2007, 06:31 AM
#4
Re: Set default value for Combo Box
Instead of searching for the text in the loop (as logan suggested) you could also use CComboBox::FindStringExact method
-
April 13th, 2007, 06:34 AM
#5
Re: Set default value for Combo Box
Well I assumed that the values was 1,2,3,4,5,6 in that order.
If not, do this;
Code:
int itemToSelect = combo.FindStringExact(0,_T("3"));
combo.SetCurSel(itemToSelect);
EDIT: VIctor was faster, as usual
Regards,
Laitinen
-
April 13th, 2007, 06:45 AM
#6
Re: Set default value for Combo Box
Originally Posted by laitinen
...
EDIT: VIctor was faster, as usual
Uhhm, i would say: "... as an exception"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|