CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: CComboBox

  1. #1
    Join Date
    Nov 2011
    Posts
    18

    CComboBox

    Hi!

    Is there any function to get the total number of items in a Combobox?

    Laura

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CComboBox

    Quote Originally Posted by laephy View Post
    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

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

  4. #4
    Join Date
    Nov 2011
    Posts
    18

    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?

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CComboBox

    I don't understand the question.

  6. #6
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: CComboBox

    Quote Originally Posted by laephy View Post
    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

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CComboBox

    Quote Originally Posted by laephy View Post
    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

  8. #8
    Join Date
    Nov 2011
    Posts
    18

    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
  •  





Click Here to Expand Forum to Full Width

Featured