1

I have this code:

void CChristianLifeMinistryEditorDlg::UpdateDatesCombo()
{
    for (int iDate = 0; iDate < m_cbDates.GetCount(); iDate++)
    {
        auto *pEntry = (CChristianLifeMinistryEntry*)m_cbDates.GetItemDataPtr(iDate);
        if (pEntry != nullptr)
        {
            COMBOBOXEXITEM cmbItem;
            CString strDateOriginal = _T("");
            CString strDateNew = FormatWeekOfMeetingText(pEntry->GetMeetingDate());

            // Get the existing item from the combo
            cmbItem.mask = CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_TEXT | CBEIF_LPARAM;
            cmbItem.iItem = iDate;
            cmbItem.pszText = strDateOriginal.GetBuffer(_MAX_PATH);
            cmbItem.cchTextMax = _MAX_PATH;
            m_cbDates.GetItem(&cmbItem);
            strDateOriginal.ReleaseBuffer();

            // Update the text
            strDateNew = FormatWeekOfMeetingText(pEntry->GetMeetingDate());
            cmbItem.pszText = strDateNew.GetBuffer(_MAX_PATH);
            m_cbDates.SetItem(&cmbItem);
            strDateNew.ReleaseBuffer();
        }
    }
}

It works fine and correctly changes the drop list from one language to another.

However, the existing value in the combo is not updated until I hover the mouse over the control.

I have tried m_cbDates.UpdateWindow and it makes no difference.

I saw this question but my issue relates to the text and not the image.

How do I get the CComboBoxEx to force it to show the updated text value?

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164

1 Answers1

2

In order to update the control you'll have to call:

m_cbDates.RedrawWindow (NULL, NULL, 
    RDW_INVALIDATE | RDW_FRAME | 
    RDW_UPDATENOW | RDW_ALLCHILDREN);

Read more about RedrawWindow here.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Andrew Komiagin
  • 6,446
  • 1
  • 13
  • 23