Link to home
Start Free TrialLog in
Avatar of appleby
appleby

asked on

UpdateData not working with Dropdown style CComboBox

I understand that UpdateData is not supposed to work with the Droplist style of combobox, but I have a DropDown style combobox that it is not working with.  It is a pretty simple set of code, just created the dialog in the resources and had classwizard add member variables for 2 combo boxes.  From the ON_CBN_SELCHANGE handler I tried setting the member variable by calling UpdateData().  It returns 1 but the value of the member variable does not change.  I tested the value in the combobox by immediately calling GetLBText to retrieve the data, and that works fine.

What could I be doing that the UpdateData() is not working?
Urgently awaiting an answer,
appleby
Avatar of appleby
appleby

ASKER

Here are snippets of the key pieces of code:

void CVersionPage::DoDataExchange(CDataExchange* pDX)
{
     CDialog::DoDataExchange(pDX);
     //{{AFX_DATA_MAP(CVersionPage)
     DDX_CBString(pDX, IDC_VERSION, m_strVersion);
     //}}AFX_DATA_MAP
}

void CVersionPage::OnSelchangeVersion()
{
    UpdateData(); // I examine the value of m_strVersion here and find no change.
}

The declaration in the .h file:
// Dialog Data
     //{{AFX_DATA(CVersionPage)
     enum { IDD = IDD_VERSION_DLG };
     CString     m_szVersion;
     //}}AFX_DATA

Avatar of appleby

ASKER

Oops, I copied the .h snippet just now from an old copy of the file - indeed I did change all the names to m_strVersion, so I do not really have a mismatch between m_szVersion and m_strVersion as it appears.  The problem exists with m_strVersion as the filename in all locations.
Sorry for the confusion.
I seem to recall having this problem a long time ago too.   The call to UpdateData in the CBN_SELCHANGE event returns the previous value of the edit box not the current value.

An idea would be to try CBN_EDITCHANGE.

Failing that why not just use GetLBText, which you know works OK?
Avatar of appleby

ASKER

Ok, I just tried CBN_EDITCHANGE (which seems like a good idea since it gets called after the text has changed) but it made no difference.  Thanks for the suggestion though.

Yes, I am using GetLBText for now but would prefer to use UpdateData if I could make it work.  

I got the same problem few days ago and solved it with CBN_SELCHANGE this way:

void CUnit::OnSelChangeComboOIT()
{
     UpdateData(TRUE);
     int iOIT = m_cbOIT.GetCurSel();
//m_cbOIT = member variable associated to combobox
     
     if(iOIT == NOIDENTIFICATION)
     {
         .....

Maybe it could help you
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial