Solved

Two CListCtrls on a dialog

Posted on 2006-06-16
7
253 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 136
Creating Labels and Frequency list style reports in SAS code 9 98
how do i create updater to My Activex application? 3 88
haveThree challenge 22 118
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

810 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