Use of list control in MFC

1. In the properties of list_control, select VIEW as Report:
Insert picture description here

2. Add variables to the list control control:
Insert picture description here

3. In the created dialog box, find the code added in the OnInitDialog() function:

// TODO: 在此添加额外的初始化代码

	m_listcontrol.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); 
	// 样式设置为整行选择、网格线
	m_listcontrol.InsertColumn(0, _T("序 号"), LVCFMT_CENTER, 80);
	m_listcontrol.InsertColumn(1, _T("诗 句"), LVCFMT_CENTER, 160);
	m_listcontrol.InsertColumn(2, _T("     "), LVCFMT_CENTER, 160);

	int nRow = m_listcontrol.InsertItem(0, _T("1"));
	m_listcontrol.SetItemText(nRow,1,_T("假如生活欺骗了你"));
	int nRow1 = m_listcontrol.InsertItem(1, _T("2"));
	m_listcontrol.SetItemText(nRow1, 1, _T("不要悲伤"));
	int nRow3 = m_listcontrol.InsertItem(2, _T("3"));
	m_listcontrol.SetItemText(nRow3, 1, _T("不要心急"));
	int nRow4 = m_listcontrol.InsertItem(3, _T("4"));
	m_listcontrol.SetItemText(nRow4, 1, _T("忧郁的日子里需要镇静"));
	int nRow5 = m_listcontrol.InsertItem(4, _T("5"));
	m_listcontrol.SetItemText(nRow5, 1, _T("相信吧"));
	int nRow6 = m_listcontrol.InsertItem(5, _T("6"));
	m_listcontrol.SetItemText(nRow6, 1, _T("快乐的日子"));
	int nRow7 = m_listcontrol.InsertItem(6, _T("7"));
	m_listcontrol.SetItemText(nRow7, 1, _T("将会来临"));

4. Final output style:
Insert picture description here

Summary: The
above four steps can complete the simple use of list control.

Guess you like

Origin blog.csdn.net/qq_27538633/article/details/107418603