当前位置:网站首页>[MFC development (17)] advanced list control list control
[MFC development (17)] advanced list control list control
2022-07-01 08:41:00 【Demo. demo】
1. Introduce
ListCtrl Advanced list control is also a common control in our usual programming process , It generally involves report presentation 、 Record and display , Need to be ListCtrl Advanced list control . for example : Task manager , File list , And so on ListCtrl Advanced list control .


Introduction to common attributes :
Edit Lables Whether the node can be edited

View Used to set the style of advanced list controls , There are four styles

Icon: For each item Show large icons

Small Icon: For each item Show small icons

List: Displays a list of... With small icons item

Report: Show item Detailed information

2. Common methods
(1) First, add variables to the control

(2) Set extended style
// Get an extended style
DWORD style = m_listctrl.GetExtendedStyle();
// Add the style of gridline and the style selected in the whole row, and add a selection box in front
style |= LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES;
// Set extended style
m_listctrl.SetExtendedStyle(style);(3) Add columns
// Add columns ,0--- Serial number , The second parameter shows the content ,
// The third parameter shows the alignment , The fourth parameter is the width displayed in the header
m_listctrl.InsertColumn(0, _T(" First column "), LVCFMT_CENTER, 50);
m_listctrl.InsertColumn(1, _T(" Second column "), LVCFMT_CENTER, 50);
m_listctrl.InsertColumn(2, _T(" The third column "), LVCFMT_CENTER, 50);(4) Add lines and line contents
// Insert line contents
// Add to the end
m_listctrl.InsertItem(m_listctrl.GetItemCount(),_T(" first line "));
// You can set the contents of a row and a column , The parameters are row , Column , Text content
m_listctrl.SetItemText(0,0, _T("111"));
m_listctrl.SetItemText(0,1, _T("222"));
m_listctrl.SetItemText(0,2, _T("333"));
(5) Set to select a row and uncheck
Choose
void CMFC_Test1Dlg::OnBnClickedButton21()
{
// TODO: Add control notification handler code here
// Set highlight
m_listctrl.SetFocus();
// Set to select a row
m_listctrl.SetItemState(1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
}Uncheck the selected
void CMFC_Test1Dlg::OnBnClickedButton24()
{
// TODO: Add control notification handler code here
m_listctrl.SetItemState(1,0, LVIS_SELECTED | LVIS_FOCUSED);
}
(6) Traverse every line in the control
void CMFC_Test1Dlg::OnBnClickedButton25()
{
// TODO: Add control notification handler code here
// First, get how many rows
int ncount = m_listctrl.GetItemCount();
// Go through every line
for (int i = 0; i < ncount; i++){
// Single acquisition i+1 First column of row 、 Second column 、 The third column
CString str1 = m_listctrl.GetItemText(i, 0);
CString str2 = m_listctrl.GetItemText(i, 1);
CString str3 = m_listctrl.GetItemText(i, 2);
}
}(7) Get the selected row
// Get the currently selected row
// First get the position
POSITION pos = m_listctrl.GetFirstSelectedItemPosition();
while (pos){
// Get the index of the selected row according to the position
int row_idx = m_listctrl.GetNextSelectedItem(pos);
CString str_idx;
str_idx.Format(_T("%d"), str_idx);
MessageBox(str_idx);
}(8) Get the row selected in the multiple check box
void CMFC_Test1Dlg::OnBnClickedButton26()
{
// TODO: Add control notification handler code here
// First, get how many rows
int ncount = m_listctrl.GetItemCount();
// Go through every line
for (int i = 0; i < ncount; i++){
BOOL bcheck = m_listctrl.GetCheck(i);
if (bcheck){
CString check_idx;
check_idx.Format(_T(" The first %d Line is checked "), i);
MessageBox(check_idx);
}
}
}
(9) Delete row
void CMFC_Test1Dlg::OnBnClickedButton27()
{
// TODO: Add control notification handler code here
// Delete a line
m_listctrl.DeleteItem(0);
// Delete all rows
m_listctrl.DeleteAllItems();
}Note that after deleting a row , The index of all remaining rows will change , For example, delete 0 That's ok , Then delete 1 The line has changed. 0 That's ok
(10) Edit the specified line text

It should be noted that you should make it editable , Need to set the control property clock Edit Labels by True
First, add two events , Start and end editing


void CMFC_Test1Dlg::OnLvnBeginlabeleditList2(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
// TODO: Add control notification handler code here
*pResult = 0;
}
void CMFC_Test1Dlg::OnLvnEndlabeleditList2(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
// TODO: Add control notification handler code here
// The three parameters are rows in turn , Column , Input content
m_listctrl.SetItemText(pDispInfo->item.iItem, pDispInfo->item.iSubItem, pDispInfo->item.pszText);
*pResult = 0;
}Note that you can only edit ( The index for 0 Of ) The first 1 Column text , Other columns cannot be edited .
边栏推荐
- TypeError: __init__() got an unexpected keyword argument ‘autocompletion‘
- 机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现
- The era of low threshold programmers is gone forever behind the sharp increase in the number of school recruitment for Internet companies
- 2022 ordinary scaffolder (special type of construction work) examination question bank and the latest analysis of ordinary scaffolder (special type of construction work)
- Glitch free clock switching technology
- It is designed with high bandwidth, which is almost processed into an open circuit?
- Yolov5 advanced 7 target tracking latest environment setup
- 5mo3 UHI HII HII 17mn4 19Mn6 executive standard
- [no title] free test questions for constructor municipal direction general foundation (constructor) and theoretical test for constructor municipal direction general foundation (constructor) in 2022
- 《单片机原理及应用》—定时器、串行通信和中断系统
猜你喜欢

Gateway-88

The use of word in graduation thesis

Huawei machine test questions column subscription Guide

避免按钮重复点击的小工具bimianchongfu.queren()

Share 7 books I read in the first half of 2022

个人装修笔记

Principle and application of single chip microcomputer - principle of parallel IO port

机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现

Principle and application of single chip microcomputer - off chip development

What is the material of 16MnDR, the minimum service temperature of 16MnDR, and the chemical composition of 16MnDR
随机推荐
Nacos - 服务发现
There are many problems in sewage treatment, and the automatic control system of pump station is solved in this way
19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
挖财打新股安全吗
Nacos - 配置管理
Do you know how data is stored? (C integer and floating point)
Li Kou 1358 -- number of substrings containing all three characters (double pointer)
Matlab [function derivation]
View drawing process analysis
机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现
华为机试真题专栏订阅指引
How can enterprises and developers take the lead in the outbreak of cloud native landing?
你了解数据是如何存储的吗?(C整型和浮点型两类)
C语言指针的进阶(下)
Agrometeorological environment monitoring system
【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】
Matlab tips (23) matrix analysis -- simulated annealing
yolov5训练可视化指标的含义
MAVROS发送自定义话题消息给PX4
电脑小技巧