none
CComboBox as Edit box On click other button in mfc RRS feed

  • Question

  • Hi friends!!

    i have a combo box and one pushbutton in newly registered, CWnd derived custom control class;

    i created Combo box in CBS_DROPDOWNLIST style. i want this to become an EDIT control (i.e CBS_DROPDOWN) on click on a PUSHBUTTON. when editing completes i will press ENTER key.

    When press enter key the data from the edit box should go to combo list. how can i do this?

    In custom control class PreTranslateaMsg() is not working.

    Monday, June 17, 2013 1:49 PM

Answers

All replies

  • My gut feeling is you probably won't have a lot of luck changing the style dynamically.  I would probably approach things by having two combo boxes, one of each style, then showing and hiding them based on the button push.
    Monday, June 17, 2013 1:53 PM
  • Oho thanks. i had same opinion before. thats why i tried to create an EDIT box by hiding combo box on click button; it works fine; BUT

    i am not able handle  ENTER KEY (VK_RETURN) message. I was thinking when i pressed enter key i could be able hide edit box and show combo box and the data entered in edit box can be inserted in combo list... how to handle VK_RETURN message in custom control?

     

     

    • Edited by Ning's Monday, June 17, 2013 2:24 PM
    Monday, June 17, 2013 2:04 PM
  • Try the other way round. Use CBS_DROPDOWN style and make the edit control in the combo box readonly by default and on click of button make it editable.

    To retrieve the edit control of a combo box use: GetComboBoxInfo(). hwnditem is the handle to the edit control.

    http://msdn.microsoft.com/en-us/library/windows/desktop/bb775798(v=vs.85).aspx

    Just a thought!


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    Monday, June 17, 2013 2:55 PM
    Moderator
  • yeah. i done something like this working fine.

    m_CEditbox = (CEdit*)m_CCombo->GetWindow(GW_CHILD);
    m_CEditbox->EnableWindow(TRUE);
    AddClick=TRUE;
    m_CEditbox->SetReadOnly(AddClick);

    after i click pushbutton, i'll make SetReadonly(FALSE);

    Now I need something like this.

    when upon entering text in edit box of combo the list box of combo should show the possibilities. how to do that?

    Thursday, June 20, 2013 4:53 AM
  • yeah. i done something like this working fine.

    m_CEditbox = (CEdit*)m_CCombo->GetWindow(GW_CHILD);
    m_CEditbox->EnableWindow(TRUE);
    AddClick=TRUE;
    m_CEditbox->SetReadOnly(AddClick);

    after i click pushbutton, i'll make SetReadonly(FALSE);

    Now I need something like this.

    when upon entering text in edit box of combo the list box of combo should show the possibilities. how to do that?

    Try below code

    COMBOBOXINFO info = { sizeof(COMBOBOXINFO) }; GetComboBoxInfo(m_Combo.m_hWnd, &info); ::SendMessage( info.hwndItem, EM_SETREADONLY, TRUE, 0 );

    // Set readonly false on click

    ::SendMessage( info.hwndItem, EM_SETREADONLY, FALSE, 0 );




    Thanks, Renjith V R

    Thursday, June 20, 2013 3:42 PM
  • Renjith V R

    that's working.

    but i want something like this. like below example. http://www.codeproject.com/Articles/489189/Group-Combo-Box#AutocompletingEnteredText

    but i don't know why, that solution itself is not opening in VS2005. even .exe

    the requirement is that. while giving input to the combo box the list has to show possible items from list.


    Friday, June 21, 2013 5:45 AM
  • SHAutoComplete coupled with IAutoComplete does exactly that (that's what I understand after reading docs). I've personally used ShAutoComplete but haven't used IAutoComplete. Reading through the docs tells me that these should help you...

    ShAutoComplete

    http://msdn.microsoft.com/en-us/library/windows/desktop/bb759862(v=vs.85).aspx

    Using AutoComplete...

    http://msdn.microsoft.com/en-us/library/windows/desktop/bb776884(v=vs.85).aspx

    From the above link...

    Adding Autocomplete Functionality to Your Application

    An application can add autocomplete functionality to an edit control in two ways:

    • SHAutoComplete is a simple function that can autocomplete a file path or URL.
    • IAutoComplete interface is exposed by the autocomplete object (CLSID_AutoComplete). It allows applications to initialize, enable, and disable the object. IAutoComplete allows more control over autocomplete sources, including the ability to add a custom source. The remainder of this topic discusses the use of IAutoComplete. See How To Enable Autocomplete Manually for specific usage examples.

    Read on...

    Looks we've got a sample as well...

    http://msdn.microsoft.com/en-us/library/windows/desktop/hh127437(v=vs.85).aspx

     


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.



    Friday, June 21, 2013 7:00 AM
    Moderator
  • Renjith V R

    that's working.

    but i want something like this. like below example. http://www.codeproject.com/Articles/489189/Group-Combo-Box#AutocompletingEnteredText

    but i don't know why, that solution itself is not opening in VS2005. even .exe

    the requirement is that. while giving input to the combo box the list has to show possible items from list.


    Oh sorry you said it is working fine. You can use the same sample in code project. You cannot open it because, your system does not have VS2010 and run time. You can either install VS2010 in your machine or create a new project in VS 2005 and manually add the files to it.  Hope below tool will help you

    Visual Studio Project Converter


    Thanks, Renjith V R

    Friday, June 21, 2013 1:38 PM