I have a combobox set to list (that means it acts as only a dropdown, not an edit control), and I have added 3 items to it, but when I click the combo box to show the drop down list, all I see is a small black line appear right below the combo box, and no list!
What do I have to do to fix this?
I figured other people had encountered this issue before, so I didn't bother posting any code. I have a wrapper class for combo boxes, so it would look a bit messy if I posted it. Nevertheless, if you need code, please request it!
There is a small trick: Click in the resource editor on the button of the combobox. This will enable to change the size of the listbox. Just size it vertically then. With clicking on the button again will help you to get back to the original state.
is there any other way to set the size of dropdown list automatically/dynamically, something like "CB_Autoheight" or so? Do i really have to send the CB_SETITEMHEIGHT meessage each time i add or remove an item?
The Dialog is shown to the user and base on his/her interaction (choice) the CB is being updated (btw - by using that ADO you helped me with). Now, because the size is still set to 15, the elements in dropdown list are not shown to the user so i need to "extend" it accordingly to the number of items added.
I've tried to manually (in the resources.rc) set the 15 to e.g. 100 pixels but then the list after rolling down is always 100pix long which does not look too pretty (if the user adds e.g. only 3 entries). So this is the reason i wanna have it dynamically resized.
I've went thru the MSDN doc and could not find any param that woudl do the resizing automatically on the update and the only one way seems to be CB_GETITEMHEIGHT + new pixels = CB_SETITEMHEIGHT. and of course i can do it this way but i wanna learn C++ and some good practices (like no unnecessary code) so no "workarounds" are allowed! :-)
Well, have a look at this example: A Dynamically-Resized Combo Box
It is MFC, but you could do the same with plain Win32. Just subclass a combobox and implement a procedure to resize window by its dropdown...
hmm so it means that there is no automatic way and this needs to be coded.
example given by you looks good and does it by usign the SetWindowPos where CB is the window, i was going to do very similar thing by using CB_SETITEMHEIGHT. i will check at home and past the final code.
I know but the items are added dynamically during the runtime.
The time of creating the CB, i don;t know what the number of elements it will contain.
You don't have to know that. What you set up is the height of the dropping down list. In case current items fit into the height, it will depend on the number of items in the list. But once those overall height exceeds the predefined height, the list will show scroll bar, but the predefined height remains unchanged.
Originally Posted by berkov
hmm so it means that there is no automatic way and this needs to be coded.
The dynamically growing list height contradicts with basic Windows UI design guidelines, so breaking the rules must be thought out very thoroughly.
just tried this.
i even updated the CB to have the autoscroll:
COMBOBOX IDC_inv_type, 65, 28, 72, 35, CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_TABSTOP |ES_AUTOHSCROLL
and then tried with CBS_AUTOHSCROLL...
still, the dropdownlist has exactly the same size that i set in the resources.rc - in this case it's 35 and it's capable to hold only 2 items and the scroll does not appear.
i guess i will have to code the size myself - can't believe microsoft did not think about it.
What version of VS and SDK you are using?
Is it Win32 app or MFC based? What version of windows you are testing your app?
I wrote sample program with initial number of items set to 20, and after selecting and removing some items, I add 15 new items. Combo drop box resized accordingly, and uses a scroll bar.
The combo was inserted into a dialog and I did not make any modification.
Is it possible to post a sample app to demonstrate the problem you have?
There are only 10 types of people in the world: Those who understand binary and those who do not.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.