Udostępnij za pośrednictwem


Changing List Control Styles

You can change the window style of a list control (CListCtrl) at any time after you create it. By changing the window style, you change the kind of view the control uses. For example, to emulate the Explorer, you might supply menu items or toolbar buttons for switching the control between different views: icon view, list view, and so on.

For example, when the user selects your menu item, you could make a call to GetWindowLong to retrieve the current style of the control and then call SetWindowLong to reset the style. For more information, see Using List View Controls in the Windows SDK.

Available styles are listed in Create. The styles LVS_ICON, LVS_SMALLICON, LVS_LIST, and LVS_REPORT designate the four list control views.

Extended Styles

In addition to the standard styles for a list control, there is another set, referred to as extended styles. These styles, discussed in Extended List View Styles in the Windows SDK, provide a variety of useful features that customize the behavior of your list control. To implement the behavior of a certain style (such as hover selection), make a call to CListCtrl::SetExtendedStyle, passing the needed style. The following example demonstrates the function call:

m_ListCtrl.SetExtendedStyle(LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE);

Note

For hover selection to work, you must also have either LVS_EX_ONECLICKACTIVATE or LVS_EX_TWOCLICKACTIVATE turned on.

See Also

Reference

Using CListCtrl

Concepts

Controls (MFC)