[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1703
  • Last Modified:

CListCtrl Checkbox Readonly

I have a CListCtrl that displays a checkbox in the left column. I want to programatically check and uncheck these checkboxes but not allow the user to do so.
0
Rxd
Asked:
Rxd
1 Solution
 
abancroftCommented:
I don't think there is an API to do this.

If you are using the standard (IE4) LVS_EX_CHECKBOXES style, just trap the user click and set the check to whatever is stored in your data structure i.e. programmatically undo the users action.

Alternatively, implement the checkboxes your self (as state icons). Then you have complete control.
0
 
wildyCommented:
As abancroft says, there is no API to do this: you must do it yourself


void CProduzMainDlg::OnItemChangedListMatr(NMHDR* pNMHDR, LRESULT* pResult)
{
      NMLISTVIEW* pNMListView = (NMLISTVIEW*)pNMHDR;
      
      /* If the event is not fired because of any change in individual items then the oldstate and
      newstate members of pNMListView are not used.  So check for that.*/
      
      if ((!pNMListView->uOldState && !pNMListView->uNewState) || bCheckingFromCode)
            return;
      
      int matr = pNMListView->iItem;
      if (matr == -1)
            return;
      
      bCheckingFromCode = true;
      m_listMatr.SetCheck(matr, FALSE);
      bCheckingFromCode = false;
}

Look at this code...
bCheckingFromCode is a member of the dialog class (or view or whatever) and is used because a SetCheck fires an LVM_ITEMCHANGED, so if u don't do this you loop and loop forever.

Change the SetCheck call whit something appropriate to u (e.g. check the item state and set or reset the check)

Hope this helps
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now