打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
MFC表格控件的简单使用

一、VS2008建立基于对话框的MFC程序,添加List控件,添加控件变量m_List,CListCtrl型

二、设置格式

[c-sharp] view plaincopy?
  1. m_List.ModifyStyle( 0, LVS_REPORT );               // 报表模式   
  2. m_List.SetExtendedStyle(m_List.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);  
  3.                                                       // 间隔线+行选中  
 三、插入表头

  1. m_List.InsertColumn(0,"端口号");  
  2. m_List.InsertColumn(1,"IP");  
 

四、设置列宽

  1. CRect rect;  
  2. m_List.GetClientRect(rect); //获得当前客户区信息   
  3. m_List.SetColumnWidth(0, rect.Width() / 2); //设置列的宽度。   
  4. m_List.SetColumnWidth(1, rect.Width() / 2);  
 五、插入行数据

  1. m_List.InsertItem(0, "2354");  
  2. m_List.SetItemText(0, 1, "192.168.0.2");  

六、查找第一列数据

  1. LVFINDINFO info;  
  2. int nIndex;  
  • info.flags = LVFI_PARTIAL|LVFI_STRING;  
  • info.psz = "1234";  
  • nIndex = m_List.FindItem(&info)  // nIndex为行数(从0开始)  
  • 七、查找其他列数据需遍历

    1. int nRows = 0;  
    2. nRows = m_List.GetItemCount();  
    3. int nIndex = 0;  
  • for(int i = 0; i < nRows; i++)  
  • {  
  •     if(m_List.GetItemText(i, 5).Find("1234") >= 0)  
  •     {  
  •         nIndex = i;  
  •     }  
  • }  
  • 八、删除一行

    1. m_List.DeleteItem(nIndex);  

    本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
    打开APP,阅读全文并永久保存 查看更多类似文章
    猜你喜欢
    类似文章
    【热】打开小程序,算一算2024你的财运
    VS2010/MFC编程入门之二十九(常用控件:列表视图控件List Control 下)
    用mfc实现组合框控件下拉列表显示
    MFC基本控件使用——列表控件(ListCtrl)
    Vertical lines for column borders
    mfc的static控件的自动换行的实现
    MFC控件的使用
    更多类似文章 >>
    生活服务
    热点新闻
    分享 收藏 导长图 关注 下载文章
    绑定账号成功
    后续可登录账号畅享VIP特权!
    如果VIP功能使用有故障,
    可点击这里联系客服!

    联系客服