AlwaysLearningNewStuff
AlwaysLearningNewStuff

Reputation: 3031

Dynamically adjust the width of combobox so the entire string can be shown

I am using a combobox control to show names stored in a database ( I need to preserve space, that is why I use it instead of a listview, for example ).

My problem is that sometimes text is longer than the combobox so part of it can not be seen.

Is there a way to resize combobox' listbox so it can entirely show text, or at least to enable some kind of horizontal scrolling so the user can scroll to see the entire text?

Looking through combobox documentation, I haven't found any style that can solve my problem. Trying to add WS_HSCROLL as a style in my CreateWindowEx call didn't help either. Thank you.

Upvotes: 0

Views: 1502

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596256

You are looking for the CB_SETHORIZONTALEXTENT message.

An application sends the CB_SETHORIZONTALEXTENT message to set the width, in pixels, by which a list box can be scrolled horizontally (the scrollable width). If the width of the list box is smaller than this value, the horizontal scroll bar horizontally scrolls items in the list box. If the width of the list box is equal to or greater than this value, the horizontal scroll bar is hidden or, if the combo box has the CBS_DISABLENOSCROLL style, disabled.

Parameters

wParam
Specifies the scrollable width of the list box, in pixels

lParam
This parameter is not used.

Upvotes: 2

Related Questions