Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4094462
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:44:53+00:00 2026-05-20T19:44:53+00:00

The MFC offers a function called DDX_CBIndex to get the Index of the current

  • 0

The MFC offers a function called DDX_CBIndex to get the Index of the current selected ComboBox item. But in most cases I’m not interested about the index, instead I want to get the 32 bit application-supplied value, which I get when calling GetItemData. Therefore I always have to override OnOk and use GetCurSel and GetItemData to retrieve this value.

Is there a more elegant way to get/set the CComboBox item not depending on the index but depending on the application-supplied 32 bit value?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:44:53+00:00Added an answer on May 20, 2026 at 7:44 pm

    I had a partial solution to this problem, but using the suggestion of @taspeotis, I wrote this, which seems to work pretty well.

        template <class T>
    void DDX_CBData(CDataExchange* pDX, int nIDC, T& data)
    {
        HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
        if (pDX->m_bSaveAndValidate)
        {
            int index = static_cast<int>(::SendMessage(hWndCtrl, CB_GETCURSEL, 0, 0L));
            data = (index == CB_ERR ? NULL : reinterpret_cast<T>(::SendMessage(hWndCtrl, CB_GETITEMDATA, index, 0L)));
        }
        else
        {
            int count = static_cast<int>(::SendMessage(hWndCtrl, CB_GETCOUNT, 0, 0L));
            for (int i = 0; i != count; ++i)
            {
                if (reinterpret_cast<T>(::SendMessage(hWndCtrl, CB_GETITEMDATA, i, 0L)) == data)
                {
                    ::SendMessage(hWndCtrl, CB_SETCURSEL, i, 0L);
                    return;
                }
            }
            ::SendMessage(hWndCtrl, CB_SETCURSEL, -1, 0L);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

c++ MFC compile error error C2470: 'CMySink' : looks like a function definition, but
Is MFC's document view architecture the same as MVC pattern or not
I have a multithreading MFC application. But I don't want to have hacky code
I am learning MFC and find it not that easy to use. I've heard
In MFC how to remove a menu-item of POPUP type. RemoveMenu() either take ID
The MFC ribbon bar has a menu item labelled 'Minimize the ribbon'. When you
The MFC combobox is really a wierd design. I use drop list type combo
(MFC Question) What's the best way to determine the current displayed client area in
In MFC I'm trying to set a null handler timer (ie. no windows). But
I have a MFC C++(not managed) program and I need to generate a xls.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.