分享

MFC表格控件的简单使用

 寂静如河 2012-02-20

一、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;  
  3. info.flags = LVFI_PARTIAL|LVFI_STRING;  
  4. info.psz = "1234";  
  5. nIndex = m_List.FindItem(&info)  // nIndex为行数(从0开始)  

七、查找其他列数据需遍历

  1. int nRows = 0;  
  2. nRows = m_List.GetItemCount();  
  3. int nIndex = 0;  
  4. for(int i = 0; i < nRows; i++)  
  5. {  
  6.     if(m_List.GetItemText(i, 5).Find("1234") >= 0)  
  7.     {  
  8.         nIndex = i;  
  9.     }  
  10. }  

八、删除一行

  1. m_List.DeleteItem(nIndex);  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多