Retrieving selected items


Application Security Testing: An Integral Part of DevOps

To retrieve the index of the first selected item use GetNextItem(). As its name implies, you can use also use the GetNextItem() function to retrieve the index of the next selected item. The code below prints out the indices of all selected items to the debug window.
// This code prints out the indices of selected items to debug win
 int i = GetNextItem( -1, LVNI_ALL | LVNI_SELECTED);
 while( i != -1 )
	TRACE("%d\n", i );
	i = GetNextItem( i, LVNI_ALL | LVNI_SELECTED);


  • some modification

    Posted by Legacy on 04/21/2002 12:00am

    Originally posted by: Alexey Popov

    int start=-1;

    start=ListView_GetNextItem(m_hWndListView, start, LVNI_SELECTED);
    if (start!=-1)
    // put your code here
    while (/*start != -1*/ true);

  • SetItemData Works fine for me with a Dlg

    Posted by Legacy on 01/26/2001 12:00am

    Originally posted by: David Smulders

    m_List.SetItemData(nRow, reinterpret_cast<DWORD>(new CString(m_Text)));

    void CMyDlg::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)

    if (pNMListView && pNMListView->uOldState != pNMListView->uNewState)
    if ((pNMListView->uNewState & LVIS_SELECTED) == LVIS_SELECTED)
    CString* pString = reinterpret_cast<CString*>(m_List.GetItemData(pNMListView->iItem));

    if (pString)
    m_Output= *pString;

    *pResult = 0;

  • Example did not work; but MSDN solution did

    Posted by Legacy on 02/06/2000 12:00am

    Originally posted by: Gerard Nicol

    When using the defined solution; loop kept returning item 0.
    Although, in theory it should have worked.

    The solution from MSDN is:

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

    POSITION pos = pList->GetFirstSelectedItemPosition();
    if (pos == NULL)
    TRACE0("No items were selected!\n");
    while (pos)
    int nItem = pList->GetNextSelectedItem(pos);
    TRACE1("Item %d was selected!\n", nItem);
    // you could do your own processing on nItem here

    This did work.

  • So simple, yet so perfect . . .

    Posted by Legacy on 09/15/1999 12:00am

    Originally posted by: Andon M. Coleman

    Good work yet again, Zafir :)

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Discover the best practices from HPE’s IT Advisory Consulting Services for migrating and transforming applications in Hybrid IT by capitalizing on innovative platforms, modern application architectures, agile development tools and proven methodologies. There are a number of challenges our customers face when migrating and transforming applications for a Hybrid IT environment. This guide provide proven strategies and application approaches that can help them understand and reduce risks and complexity.

  • The Internet of Things (IoT), a growing network of physical devices with Internet connectivity, can collect and exchange rich data. Organizations utilizing the Enterprise of Things (EoT) are also at a greater risk for data breaches and cybersecurity threats. Healthcare organizations striving to realize the full potential of the EoT must also be able to confidentially and reliably transmit highly sensitive data between connected devices. Read this white paper to discover the best cybersecurity strategies to get …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.