mfc 列表控件

mfc 列表控件

经常使用的mfc控件:list control,记录下
 
  1. 首先将list control拖入到对话框中,然后命名ID,通过类向导,类型为control,控件变量名(m_showlist),  view改变为report报表形式
  2. 在xxxDlg.cpp::OnInitDialog()根据需要添加表头和表项内容
          eg:  
CRect rect;
m_showlist.GetClientRect(&rect);
m_showlist.SetExtendedStyle(m_showlist.GetExStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
//表头
m_showlist.InsertColumn(0,_T("身份证号"), LVCFMT_CENTER,rect.Width()/5,0);
m_showlist.InsertColumn(1,_T("姓名"), LVCFMT_CENTER,rect.Width()/5,1);
m_showlist.InsertColumn(2,_T("类型"), LVCFMT_CENTER,rect.Width()/5,2);
m_showlist.InsertColumn(3,_T("发证日期"), LVCFMT_CENTER,rect.Width()/5,3);
m_showlist.InsertColumn(4,_T("有效期"), LVCFMT_CENTER,rect.Width()/5,4);
//表项
  1. 然后通过函数 SetItemText 修改表格的内容
                  m_showlist.SetItemText(i, j, string);
                     其中,表示将第 i 列 第 j 行 内容改为 字符串 string 
                    例子:m_list_goods.SetItemText(1,2,_T("未拍卖"));