We help IT Professionals succeed at work.

Listbox sorted or unsorted

Pacman
Pacman asked
on
Medium Priority
729 Views
Last Modified: 2013-11-20
I have the following scenario:
There is a dialog template with a listbox control.
The listbox has style bit "LBS_SORT" set.

Now I want to decide AT RUN TIME if the listbox should be created with or without LBS_SORT.

I've found out that modifying the style after creation doesn't help.
I think the style must be changed before the control is created.

Any ideas how to do this?

PS: don't tell me to overwrite PreCreateWindow() of the control class. The dialog must change the control. Not the control itself.
Comment
Watch Question

Commented:
Basically, you can't do it.  Once a listbox is made, its sort/no-sort status is fixed.

Two ideas:

1) If you need sorted vs. non-sorted, sort or don't sort the items yourself as you put then into the listbox.  That way you have control.

2) Make 2 listboxes, one sorted and the other unsorted and hide the one that you do not want at the moment.

(I prefer #1 but either approach will do the trick.)
CERTIFIED EXPERT

Author

Commented:
OK this article says following:

you have 2 methods to use different styles at run-time.

a) create control dynamic
b) add two controls and hide the one you don't need

The first one doesn't help me because I have no influence on the tab order when I add the control dynamically.

The second one is a good idea. I think it would work for me.

thank you for the link.
regards
Pacman

Explore More ContentExplore courses, solutions, and other research materials related to this topic.