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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Here's a good intro on how to program a list control: http://www.codeproject.com/listctrl/listctrldemo.asp
ASKER
This is what the resulting code looked like...
void CSelectQaShipper::OnItemch angedAssoc iatedQaShi ppers(NMHD R* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
if (m_AssociatedQaShippers.Ge tItemState (pNMListVi ew->iItem, LVIS_SELECTED)) {
deselectQaShipperItem(&m_A llQaShippe rs);
}
*pResult = 0;
}
void CSelectQaShipper::OnItemch angedAllQa Shippers(N MHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
if (m_AllQaShippers.GetItemSt ate(pNMLis tView->iIt em, LVIS_SELECTED)) {
deselectQaShipperItem(&m_A ssociatedQ aShippers) ;
}
*pResult = 0;
}
void CSelectQaShipper::deselect QaShipperI tem(CListC trl *list)
{
POSITION pos = list->GetFirstSelectedItem Position() ;
if (pos != NULL) {
int nItem;
nItem = list->GetNextSelectedItem( pos);
list->SetItemState(nItem,0 ,LVIS_SELE CTED);
}
}
void CSelectQaShipper::OnItemch
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
if (m_AssociatedQaShippers.Ge
deselectQaShipperItem(&m_A
}
*pResult = 0;
}
void CSelectQaShipper::OnItemch
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
if (m_AllQaShippers.GetItemSt
deselectQaShipperItem(&m_A
}
*pResult = 0;
}
void CSelectQaShipper::deselect
{
POSITION pos = list->GetFirstSelectedItem
if (pos != NULL) {
int nItem;
nItem = list->GetNextSelectedItem(
list->SetItemState(nItem,0
}
}
Looks good, just make sure your list controls are set for single selection.
ASKER
They are - thanks for the warning!
ASKER