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

Raymond Chen

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.

0 comments

Discussion is closed.

Feedback usabilla icon