MFC- How to support multiselect in MFC Combobox?

abc abc 351 Reputation points
2021-12-17T11:03:45.327+00:00

Hi,

MFC- How to support multiselect in MFC Combobox?

Thanks

Developer technologies | C++
{count} votes

4 answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2021-12-17T11:23:17.93+00:00

    Probably the combobox is not designed and is not suitable for multiple selections. Consider an alternative: CCheckListBox.

    2 people found this answer helpful.

  2. RLWA32 49,636 Reputation points
    2021-12-17T11:24:20.703+00:00
    1 person found this answer helpful.

  3. Petrus 【KIM】 546 Reputation points
    2021-12-20T00:48:15.677+00:00

  4. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2021-12-20T03:07:05.257+00:00

    Hi, @abc abc

    You could try to create CCheckListBox by CListBox:

    1. Drag List Box to the Dialog and modify Has Strings and Owner Draw in properties:
      159312-%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE-2021-12-21-172910.jpg
    2. Add CCheckListBox m_CheckListBox; in dialog's .h file.
    3. Add snippet below in dialog's OnInitDialog() function m_CheckListBox.SubclassDlgItem(IDC_LIST1, this);
      m_CheckListBox.SetCheckStyle(BS_AUTOCHECKBOX);
      m_CheckListBox.AddString(L"Test String");
      m_CheckListBox.AddString(L"Test String");

    159188-gif1.gif

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.