CListCtrl - How to prevent an item from being deselected when user clicks elsewhere on the listbox?

I have a CListCtrl object (listbox). I understand that to make an item selected/highlighted, I can use SetItemState(nItem, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED). Subsequently, the selection/focus will follow according to the item that user has click.

But once the user clicks on elsewhere on the listbox (not on any item), the item gets deselected. How can I prevent the listbox from getting deselection? My listbox should always have one item selected. And if the user clicks elsewhere on the listbox, the item that is currently selected should not be deselected and shld stay selected/highlighted.

Which one you are using? a list box or list control. Both are different controls!!!
Go to properties of that list box (list control) in the resource editor, then select the option "Show Selection Always".

Sorry that I have confused u people... Im using a CListCtrl. The "Show Selection Always" option has alr been selected. I mean that when user clicks elsewhere on the ListCtrl. The currently selected item will be deselected and i do not want that to happen.

The standard expected way to do multiple selection is to have the user press ctrl+click (make sure you've turned off the single selection property). If you do what you say, in order to unselect everything the user has to go in and click each selected item separately, this can be annoying.

If you really want to do this, one way is to keep a list of everything that has already been selected and programatically reselect them after every click, and if a user clicks something that is already selected remove it from the list.

You might be able to control the unselecting by handling the LVN_ITEMCHANGING message, but I've never played around with that.

If that option is enabled, then the list control selected row shall become as gray when the focus moves to some other control. That gives the indication that, that row is selected. And thats the stadard behavior. It shall not stay as blue by default when focus is not there.

Yes im already getting a gray selection on the item (set in my codings) when the program first run. But subsequently once i click elsewhere on the list ctrl (not on any item), the selection highlight on the item will be lost and the listCtrl will not have any item selected. Im not doing any multi-selection thing. So that one we can put aside. Im only concern with having one item selected at a time and at least one item should be selected at all times.

And one more qn, how do i set the CListCtrl to get the focus so that by default my selected item is higlhlighted in blue?

Well the problem is that if I didnt set any item to be selected using my codings, no item will be selected in the CListCtrl at inital startup. And as i mentioned before i need at least one item to be selected at all times. From the way u say, it seems like by default at least one item should be selected when the program is run? And by default, item should not be deselected for no reason. Jus that when it lose focus it will be gray. And when it gets the focus, the selection will be in blue right?

Well it jus doesnt work for me... I am also not sure why is this so. Anyw thanks... If u have no solution for me.. I will try to solve it slowly.

Btw now when i run my program, due to the selection set in the codings, the first item in CListCtrl will be selected in gray. So i wan to set it to get the focus so that by default it can be selected in blue. So i used m_PcList.SetFocus(); The CListCtrl still do not get the focus and the item selected is still gray color. Wat is the reason?

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes. I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.
Introductio…

Introduction:
Dialogs (1) modal - maintaining the database.
Continuing from the ninth article about sudoku.
You might have heard of modal and modeless dialogs. Here with this Sudoku application will we use one of each type: a modal dialog …

This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory.
NOTE: For Outlook 2016 and 2013 perform the exact same steps.
Open a new email: Click the New email button in Outlook.
Start typing the address: …