[Webinar] Streamline your web hosting managementRegister Today

  • 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.
1 Solution
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.
As abancroft says, there is no API to do this: you must do it yourself

void CProduzMainDlg::OnItemChangedListMatr(NMHDR* pNMHDR, LRESULT* pResult)
      /* 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)
      int matr = pNMListView->iItem;
      if (matr == -1)
      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

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