A list control can be thought of as a feature-enhanced listbox that provides four styles and can display a column of multi-attribute values at the same time.
MFC uses the CListCtrl class to encapsulate the various operations of a list control.
by calling BOOL Create (DWORD dwstyle, const rect& RECT, cwnd* pParentWnd, UINT NID); Create a window in which you can use some of the following list control's specialized styles:
Lvs_icon Lvs_smallicon lvs_list lvs_report These four styles determine the appearance of the control, and can only select one of them, corresponding to: Large icon display, small icon display, list display, detailed report display
The display character of the Lvs_editlabels node can be edited, and only the first column can be edited for the report style.
Lvs_showselalways also displays the currently selected node when it loses focus.
Lvs_singlesel only one item in the list can be selected
To demonstrate, I'm building a new project.
Open, file, new
Choose MFC APP, project name optional, but must be in English, file location optional
Click Next, select Dialog-based mode, direct point completion
Click the list control and draw a range in the dialog to draw the list control
Right-click List control, point properties
In general, modify the control ID, you can name it yourself
Select report mode in the Style tab, other default
Press CTRL+W, Call out Class wizard, choose Ctestdlg, this is the name of the construction project, own name, may not be the same as me, choose member variable tag
Click Idc_list_info, also named by yourself, may not be the same as mine, add Variable
I have a name, m_xxx,
Click OK
Click on the Message Map tab, first select Ctestdlg, figure 1
Select InitDialog in the message list
Then click on the right edit code
The program will automatically navigate to the code location,
Write code on the last} sign of the code
M_listall.setextendedstyle (Lvs_ex_gridlines | Lvs_ex_fullrowselect);
M_listall.insertcolumn (0, "serial number", Lvcfmt_center);
M_listall.insertcolumn (1, "Column name 1", Lvcfmt_center);
M_listall.insertcolumn (2, "column Name 2", Lvcfmt_center);
M_listall.insertcolumn (3, "column name 3", Lvcfmt_center);
M_listall.setcolumnwidth (0,50);
M_listall.setcolumnwidth (1,80);
M_listall.setcolumnwidth (2,85);
M_listall.setcolumnwidth (3,90);
This completes the initialization, click on the red exclamation mark, compile and allow,
The next section tells you how to insert data.
How to use VC + + list control