Creating the List Control
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Creating the List Control.
How the list control (CListCtrl) is created depends on whether you're using the control directly or using class CListView instead. If you use CListView
, the framework constructs the view as part of its document/view creation sequence. Creating the list view creates the list control as well (the two are the same thing). The control is created in the view's OnCreate handler function. In this case, the control is ready for you to add items, via a call to GetListCtrl.
To use CListCtrl directly in a dialog box
In the dialog editor, add a List Control to your dialog template resource. Specify its control ID.
Use the Add Member Variable Wizard to add a member variable of type
CListCtrl
with the Control property. You can use this member to callCListCtrl
member functions.Use the Properties window to map handler functions in the dialog class for any list control notification messages you need to handle (see Mapping Messages to Functions).
In OnInitDialog, set the styles for the
CListCtrl
. See Changing List Control Styles. This determines the kind of "view" you get in the control, although you can change the view later.
To use CListCtrl in a nondialog window
Define the control in the view or window class.
Call the control's Create member function, possibly in OnInitialUpdate, possibly as early as the parent window's OnCreate handler function (if you're subclassing the control). Set the styles for the control.