Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to change Combobox style at runtime?

How to change Combobox style at runtime?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrew Allen
    wrote on last edited by
    #1

    My MFC app is using comboboxes with the CBS_DROPDOWN style (i.e. edit control + drop list). The combos are defined in a dialog template. I want to be able to switch these to CBS_DROPDOWNLIST style (i.e. static control + drop list). My difficulty is that I need to change the style AFTER the comboboxes have been created. (How) can this be done? Andrew

    E 1 Reply Last reply
    0
    • A Andrew Allen

      My MFC app is using comboboxes with the CBS_DROPDOWN style (i.e. edit control + drop list). The combos are defined in a dialog template. I want to be able to switch these to CBS_DROPDOWNLIST style (i.e. static control + drop list). My difficulty is that I need to change the style AFTER the comboboxes have been created. (How) can this be done? Andrew

      E Offline
      E Offline
      Eugene Pustovoyt
      wrote on last edited by
      #2

      m_pComboBox.ModifyStyle(...) Best regards, Eugene Pustovoyt

      A 1 Reply Last reply
      0
      • E Eugene Pustovoyt

        m_pComboBox.ModifyStyle(...) Best regards, Eugene Pustovoyt

        A Offline
        A Offline
        Andrew Allen
        wrote on last edited by
        #3

        Hi Eugene, I just tried your suggestion, but it doesn't work. My combobox is derived from CComboBox, I have a member function to do the switch void CMyComboBox::MakeStatic() { VERIFY(ModifyStyle(CBS_DROPDOWN, CBS_DROPDOWNLIST)); } I call MakeStatic() after the combo has been created, but immediately before I load the combo. The ModifyStyle() call returns TRUE - the VERIFY doesn't generate an error. I also tried ModifyStyleEx(), just in case, but it doesn't work either :confused:

        A 1 Reply Last reply
        0
        • A Andrew Allen

          Hi Eugene, I just tried your suggestion, but it doesn't work. My combobox is derived from CComboBox, I have a member function to do the switch void CMyComboBox::MakeStatic() { VERIFY(ModifyStyle(CBS_DROPDOWN, CBS_DROPDOWNLIST)); } I call MakeStatic() after the combo has been created, but immediately before I load the combo. The ModifyStyle() call returns TRUE - the VERIFY doesn't generate an error. I also tried ModifyStyleEx(), just in case, but it doesn't work either :confused:

          A Offline
          A Offline
          armentage
          wrote on last edited by
          #4

          Andrew Allen wrote: I just tried your suggestion, but it doesn't work. My combobox is derived from CComboBox, I have a member function to do the switch void CMyComboBox::MakeStatic() { VERIFY(ModifyStyle(CBS_DROPDOWN, CBS_DROPDOWNLIST)); } I've had this problem myself. What I did was create TWO combobox controls, one a dropdown and the other a dropdown list, and placed them right on top of each other. I used some other control to determine the state I wanted the "combo" in, and showed/hid the appropriate one. Actually, I had this problem with CListBox. You can't change its selection style at runtime, either.

          A 1 Reply Last reply
          0
          • A armentage

            Andrew Allen wrote: I just tried your suggestion, but it doesn't work. My combobox is derived from CComboBox, I have a member function to do the switch void CMyComboBox::MakeStatic() { VERIFY(ModifyStyle(CBS_DROPDOWN, CBS_DROPDOWNLIST)); } I've had this problem myself. What I did was create TWO combobox controls, one a dropdown and the other a dropdown list, and placed them right on top of each other. I used some other control to determine the state I wanted the "combo" in, and showed/hid the appropriate one. Actually, I had this problem with CListBox. You can't change its selection style at runtime, either.

            A Offline
            A Offline
            Andrew Allen
            wrote on last edited by
            #5

            Yep, I'm convinced ModifyStyle() doesn't work after the control has been created. I just found this article talking about Listboxes, http://www.codeproject.com/combobox/listbox_tut.asp[^] ... Changing List box Styles at Runtime It is not possible to change these styles at runtime even though ModifyStyle() may give the impression it does. If you want turn the Sort style on and off for example it is best to construct the List box by calling new and Create then deleting it and creating a new one when the style is to be changed. Alternatively you can have 2 List box superimposed and hide the one with the incorrect style. I already thought about overlapping two controls, but I have about 10 in my dialog and at the time it seemed messy in the dialog template. Looks like that's what I'll do. thanks for your help!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups