CListCtrl Item Selection??

The "List Box" in MFC has a member function that returns the index of the item selected. GetCurSel().

Can anyone tell me how to do the same thing with a List View Control(CListCtrl)
shark351Asked:
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.

chensuCommented:
CListCtrl::GetFirstSelectedItemPosition and CListCtrl::GetNextSelectedItem.

CListCtrl *pListCtrl = (CListCtrl *) GetDlgItem(IDC_YOURLISTCONTROL);
ASSERT(pListCtrl != NULL);

POSITION pos = pList->GetFirstSelectedItemPosition();
if (pos == NULL)
    TRACE0("No items were selected!\n");
else
{
    while (pos)
    {
        int nItem = pList->GetNextSelectedItem(pos);
        TRACE1("Item %d was selected!\n", nItem);
        // you could do your own processing on nItem here
    }
}
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
Vinayak KumbarSr Program ManagerCommented:
Hi,

Do the following thing to get the selected item
here m_ctrlPacketSignalListView is the control variable for that list control.

int l_iItemCount = m_ctrlPacketSignalListView.GetItemCount();
            
for(int l_iIndex = 0;l_iIndex<l_iItemCount;l_iIndex++)
{
if(m_ctrlPacketSignalListView.GetItemState(l_iIndex,LVIS_SELECTED))
{
//the l_iIndex gives u the selected item index
break;//u can break or continue
}
                  
}

Try it out.
VinExpert
0
shark351Author Commented:
Chensu,
I am using VC++ 5.0
Are the functions you mentioned not available for this version??
I tried to implement them and find documentation but failed on both.
0
chensuCommented:
I am not sure. I don't have version 5.0 to check. You may search all the source files of MFC for the function names.
0
shark351Author Commented:
Chensu,

Must not be available for version 5.0.
I will issue you the points since your answer is technically correct. In the meantime I'm using HitTest() to find which item I've selected.
Thanks
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.