WM_SELECTIONCHANGED in CListctrl

How I retrive number of selected files. I use member function GetSelected & GetNextSel... but I need to know when. Send CListCtrl some message when selection changed ???
jur9103Asked:
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.

jur9103Author Commented:
plz help
0
yazdchiCommented:
Hi jur9103,

To find out when the selection of the CListCtrl has changed, you have to trap the LVN_ITEMCHANGED message.

To find out how many items in the CListCtrl have been selected call the member function:

int SelCount = MyLstCtrl.GetSelectedCount();

To get each selected item do (for Multi-Sel ListCtrl Only):

POSITION pos = MyLstCtrl.GetFirstSelectedItemPosition();

if(pos == NULL)
 return;

int ListItemIdx;
CString TmpStr;

do
{
  // This will give you the index of one of the selected items
  ListItemIdx = MyLstCtrl.GetNextSelectedItem(pos);

// First parameter is the item index and the second parameter is the subitem index
TmpStr = MyLstCtrl.GetItemText(ListItemIdx, 0);

}
while(pos != NULL);


for a Single Selection ListCtrl do:


// This will return the index of the next selected item
// -1 means find the first selected item, if > -1 then this will start the search from the given index
int SelIdx = MyLstCtrl.GetNextItem(-1, LVNI_SELECTED);

NOTE:

int SelCount = MyLstCtrl.GetSelectedCount();

This will word for both single selection ListCtrl and Multi-Selection ListCtrl.


I hope this help.

Regards
Mohsen
0

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
jur9103Author Commented:
thnx
0
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
System Programming

From novice to tech pro — start learning today.