Solved

Two CListCtrls on a dialog

Posted on 2006-06-16
7
232 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

20 Experts available now in Live!

Get 1:1 Help Now