How to disable a WinForms TreeView node checkbox?

后端 未结 4 733
臣服心动
臣服心动 2020-11-29 08:13

I need to be able to disable some of the checkboxes in a TreeView control of a WinForms application, but there\'s no such functionality built-in to the standard

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 08:57

    TreeView.BeforeCheck -- register for this event, check whether the node is one where the checkboxes are allowed to be checked or not and, if it cannot be checked then you can cancel the event by setting the Cancel property on the TreeViewCancelEventArgs. That should hopefully prevent the user from checking those boxes but will not make for the best user-experience.

    To remove the checkboxes for the non-checkable items, you could possibly use owner-draw to draw a solid rectangle over the check-box to remove it.

提交回复
热议问题