[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Two CListCtrls on a dialog

Posted on 2006-06-16
7
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 14

Accepted Solution

by:
wayside earned 2000 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

656 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