Solved

Two CListCtrls on a dialog

Posted on 2006-06-16
7
244 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:jribble
  • 4
  • 3
7 Comments
 
LVL 14

Accepted Solution

by:
wayside earned 500 total points
ID: 16923334
You need to set up an event handler to handle the selection for either list control, remember which item is selected in each control, and then manually deselect any selections in the other control. Something along these lines:

    // item_selected1 contains the index of the item selected in ctrl 1
    UINT selstate = m_listctrl1.GetItemState(item_selected1, LVIS_SELECTED);

    // Toggle the selected state.
    m_listctrl1.SetItemState(item_selected1, ~selstate, LVIS_SELECTED);
    m_listctrl1.RedrawItems(item_selected1, item_selected1);
0
 

Author Comment

by:jribble
ID: 16923528
What event tells me when an item is selected in a CListCtrl?
0
 

Author Comment

by:jribble
ID: 16923697
I'm having a little trouble telling which event tells me when an item is selected.  Any suggestions?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:wayside
ID: 16924016
Try LVN_ITEMCHANGED .

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

Author Comment

by:jribble
ID: 16935302
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);
      }
}
0
 
LVL 14

Expert Comment

by:wayside
ID: 16935952
Looks good, just make sure your list controls are set for single selection.
0
 

Author Comment

by:jribble
ID: 16935988
They are - thanks for the warning!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 92
sum28 challenge 31 106
building a service to accessed via telnet client, want colors ? 4 83
wordcount challenge 11 108
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now