How do I create a disabled checkbox for a listview item?


A customer was using the LVS_EX_CHECK­BOXES extended listview style to get checkboxes for the listview items. However, they also wanted some items to have a disabled checkbox, which is not a feature that LVS_EX_CHECK­BOXES supports.

They solved the problem by turning off the LVS_EX_CHECK­BOXES extended style and replicating and extending the functionality of LVS_EX_CHECK­BOXES by creating a custom state imagelist consisting of enabled and disabled and checked and unchecked check boxes and setting that as the state imagelist for the listview. They also handled the mouse and keyboard notifications so that clicking on the state image or pressing the space bar toggled the check/unchecked state of the item.

So far so good.

However, there is still the issue of accessibility: Accessibility tools understand that the LVS_EX_CHECK­BOXES extended style means that the state images are check boxes, but since they aren't using that style, that leaves accessibility tools in the dark.

How do they get accessibility tools the information they need?

One way is to subclass the listview control and customize the WM_GET­OBJECT message handler by wrapping the standard accessible object for the listview, and then override the get_accState method to report the state for each item.

Alternatively, they can use Dynamic Annotation to report the state for the item. Direct Annotation is a push model, where the control pushes the current state each time it changes. Server Annotation is a pull model, where the control registers a server that produces the state of each item upon request. (Here's an example for a custom control.)

The customer chose to go with Dynamic Annotation and reported that it solved their problem.

Comments (2)
  1. IanBoyd says:

    I recently learned all about this for the first time. So i was quite tickles when I already understood all the terminology.

    A caveat for anyone using direct annotation. It’s not a piece of accessible metadata that you can set and then not have to worry about. You have to be sure to destroy it when the window is destroyed. This also gets hairy when the visual control framework happens to need to destroy and recreate the window handle out from underneath you. You’re going you have to be sure to hook every time every underlying window handle is destroyed and recreated: and destroy and recreate your direct annotation.

    Which is why in many ways it’s paradoxically easier to be responsible for every last accessible detail in your application by implementing IAccessible.

  2. Scarlet Manuka says:

    Followed the link for Dynamic Annotation, and had trouble not parsing IAccIdentity as IAccidentIty.

Comments are closed.

Skip to main content