-
March 19th, 2012, 01:53 PM
#1
CComboBox
Hi!
Is there any function to get the total number of items in a Combobox?
Laura
-
March 19th, 2012, 01:58 PM
#2
Re: CComboBox
Originally Posted by laephy
Hi!
Is there any function to get the total number of items in a Combobox?
Laura
Of course. You'll find it in the documentation for CComboBox in MSDN.
http://msdn.microsoft.com/en-us/libr...=vs.71%29.aspx
-
March 19th, 2012, 04:16 PM
#3
-
April 4th, 2012, 11:18 AM
#4
Re: CComboBox
Thank you I found the function GetCount and it works.
There is a lot of functions related to the CComboBox and I am now learning about them.
The next function I am learning is the GetCurSel function to obtain the value of the ComboBox. I have found in google both kind of writing the function
1st way:
m_Color=((CComboBox *)GetDlgItem(IDC_COLORS))->GetCurSel()
2nd way:
DDX_Control(pDX, IDC_COLORS, m_ColorList);
m_Color=m_ColorList.GetCurSel();
which is the difference between both definitions of m_Color?
-
April 4th, 2012, 11:27 AM
#5
Re: CComboBox
I don't understand the question.
-
April 4th, 2012, 11:36 AM
#6
Re: CComboBox
Originally Posted by laephy
1st way:
m_Color=((CComboBox *)GetDlgItem(IDC_COLORS))->GetCurSel()
2nd way:
DDX_Control(pDX, IDC_COLORS, m_ColorList);
m_Color=m_ColorList.GetCurSel();
which is the difference between both definitions of m_Color?
The definition of m_Color is likely the same (can't be sure, because you didn't show it), because it has nothing to do with the combo box. The difference between the two methods (assuming the DDX_Control statement is in the DoDataExchange member function of your dialog class) is that the second will give a debug assertion when the control with id IDC_COLORS does not exist or is not a combo box, whereas the first method will exhibit undefined behavior. So, use the second and never use the first.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
April 4th, 2012, 12:35 PM
#7
Re: CComboBox
Originally Posted by laephy
The next function I am learning is the GetCurSel function to obtain the value of the ComboBox.
No, it does NOT obtain "he value of the ComboBox", it obtains
The zero-based index of the currently selected item in the list box of a combo box, or CB_ERR if no item is selected.
Victor Nijegorodov
-
April 5th, 2012, 02:25 AM
#8
Re: CComboBox
Thank you for your explanation and I will use the second method.
Yes, I forgot to write the definition of m_Color, it is a integer (int m_Color) in both cases.
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
|