CListBox Unselect ??

When you have a CListBox and have selected an item then you cant unselect this item by for example clicking in the CListBox but not on an item....
I would like to be able to unselect items...

How do I solve this problem ?? Is there a message.. ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


There are 2 functions in CListBox that you can use.

SetCurSel( int nSelect );

Whice is used if you have a single select listbox.  Passing -1 will deselect all.

If you have a multiple select listbox use

SetSel( int nIndex, BOOL bSelect = TRUE );



Contains the zero-based index of the string to be set. If –1, the selection is added to or removed from all strings, depending on the value of bSelect.


Specifies how to set the selection. If bSelect is TRUE, the string is selected and highlighted; if FALSE, the highlight is removed and the string is no longer selected. The specified string is selected and highlighted by default.

Gunnar Valur

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TYBAuthor Commented:
Ok... but how do I know when to deselect all items ? I don´t always wanna deselect them....
You might for example trap the mouse click message and make it so that once someone clicks an item and it is selected it will be deselected.
TYBAuthor Commented:
Ok... tnx a lot for the help...

Btw... Happy New Millenium... : )
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.