How to change Combobox style at runtime?
-
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
-
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
m_pComboBox.ModifyStyle(...)
Best regards, Eugene Pustovoyt -
m_pComboBox.ModifyStyle(...)
Best regards, Eugene PustovoytHi 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: -
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: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.
-
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.
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!