Link to home
Start Free TrialLog in
Avatar of jribble
jribble

asked on

Two CListCtrls on a dialog

I have two list controls (CListCtrl) on a dialog.  The user is supposed to be able to select only one item out of one control, however, if I click on one item in the first list and then click on anotheritem in the second list, the application remembers the first selection.  I only want the currently highlighted item to be the selection.  Anyone had any experience with this?
ASKER CERTIFIED SOLUTION
Avatar of wayside
wayside

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jribble
jribble

ASKER

What event tells me when an item is selected in a CListCtrl?
Avatar of jribble

ASKER

I'm having a little trouble telling which event tells me when an item is selected.  Any suggestions?
Try LVN_ITEMCHANGED .

Here's a good intro on how to program a list control: http://www.codeproject.com/listctrl/listctrldemo.asp
Avatar of jribble

ASKER

This is what the resulting code looked like...

void CSelectQaShipper::OnItemchangedAssociatedQaShippers(NMHDR* pNMHDR, LRESULT* pResult)
{
      NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
      // TODO: Add your control notification handler code here
      if (m_AssociatedQaShippers.GetItemState(pNMListView->iItem, LVIS_SELECTED)) {
            deselectQaShipperItem(&m_AllQaShippers);
      }

      *pResult = 0;
}

void CSelectQaShipper::OnItemchangedAllQaShippers(NMHDR* pNMHDR, LRESULT* pResult)
{
      NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
      // TODO: Add your control notification handler code here
      if (m_AllQaShippers.GetItemState(pNMListView->iItem, LVIS_SELECTED)) {
            deselectQaShipperItem(&m_AssociatedQaShippers);
      }

      *pResult = 0;
}


void CSelectQaShipper::deselectQaShipperItem(CListCtrl *list)
{
      POSITION pos = list->GetFirstSelectedItemPosition();
      if (pos != NULL) {
            int nItem;
            nItem = list->GetNextSelectedItem(pos);
            list->SetItemState(nItem,0,LVIS_SELECTED);
      }
}
Looks good, just make sure your list controls are set for single selection.
Avatar of jribble

ASKER

They are - thanks for the warning!