Originally posted by: Ben Lam
Dear all:
I want to add CCheckBox Ctrl in other column not only the first row .
anyone can help me
thank
Originally posted by: Reichrath
Good, but do you know how to disable those Checkboxes in the CListCtrl for clicking.
Originally posted by: Jason Dunn
To display checkboxes in a CListCtrl that has the LVS_OWNERDRAWITEM style, simply add the following code to the LVN_GETDISPINFO notification handler of the parent dialog:
pItem->mask |= LVIF_STATE;
pItem->stateMask = LVIS_STATEIMAGEMASK;
pItem->state = INDEXTOSTATEIMAGEMASK(bChecked ? 2 : 1);
To determine when the check box is clicked, either use the NM_CLICK notification handler, or override OnNotify(). Then add the following code (shown for OnNotify()):
NMHDR *pHdr = (NMHDR*)lParam;
if (pHdr->code == NM_CLICK && pHdr->idFrom == IDC_SEARCH_CHECKLIST)
{
LVHITTESTINFO info;
DWORD pos = GetMessagePos();
info.pt.x = MAKEPOINTS(pos).x;
info.pt.y = MAKEPOINTS(pos).y;
m_cCheckList.ScreenToClient(&info.pt);
int index = m_cCheckList.SubItemHitTest(&info);
if (index != -1 && info.flags & LVHT_ONITEMSTATEICON)
{
... // use your data to determine if index is checked
bChecked = !bChecked;
// propagate to any selected items, if index is also selected
if (m_cCheckList.GetItemState(index, LVIS_SELECTED))
{
POSITION pos = m_cCheckList.GetFirstSelectedItemPosition();
while (pos)
{
int nItem = m_cCheckList.GetNextSelectedItem(pos);
... // get your data at nItem and set value to bChecked
bItemChecked = bChecked;
}
}
// force redraw
m_cCheckList.SetItemCount(numItems);
}
}
Reply
Originally posted by: Max Kazanowsky
if (!ListView_GetCheckState(<your handle>, <CurrentItem>))
First SetItemState statement sets the CheckBox to
"checked", second - to "unchecked" state.
{
ListView_SetItemState(<your handle>, <CurrentItem>,
INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
}
else
ListView_SetItemState(<your handle>, <CurrentItem>,
INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);
Originally posted by: Emmanuel Derriey
Hi !
LVS_EX_CHECKBOXES seems not to works with the LVS_OWNERDATA style (virtual listctrl). The space is here but no checkboxes draw !!! Why ?
Originally posted by: Chris
Good, but do you know how to determine the spacing of list items in a ListView control that is not in Report View?
ReplyOriginally posted by: abrar
How to add checkbox in subitem
ReplyOriginally posted by: Graham
In response to one of the questions concerning the logic. As far as I can tell the checkboxes use bits 12
and 13 to indicate the check state. Bit 12 is set if the box is not checked, 13 if it is.
Originally posted by: Mark Johnson
but the state never changes. The GetCheck() and all this other "enhanced" functionality
works...
I even tried copying your example directly and changing the object reference and still no change.
My list control is contained by a CFormView. Would this make a difference?
any suggestions...?
Everything you discussed works except setting the check box. What I did was derived my own control
CCheckListCtrl and added a SetCheck() member function:
void CCheckListCtrl::SetCheck(int ndx, bool flag /* = true */)
{
ListView_SetItemState(m_hWnd,
ndx,
UINT((int(_flag) + 1) << 12),
LVIS_STATEIMAGEMASK);
}
Originally posted by: Stefan
How do I set the checkbox style to 3-state in a listview control?
(like BS_AUTO3STATE for ordinary checkboxes)
/Stefan
Reply