list control这个控件用来显示数据确实挺好的,关于他的一些用法,根据我目前了解的,分为几个步骤
(1)添加 list control控件,添加list control变量 m_listcontrol,类型为control。
(2)把list control属性中View改成Report。
(3)初始化m_listcontrol,风格,表头,清空
//初始化列表控件
// //m_listcontrol.SetImageList(&m_pImageList,LVSIL_SMALL);
m_listcontrol.ModifyStyle(0,LVS_SHOWSELALWAYS);
m_listcontrol.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES| LVS_EX_TWOCLICKACTIVATE);
m_listcontrol.SetBkColor(RGB(247,247,255));
m_listcontrol.SetTextColor(RGB(0,0,0));
m_listcontrol.SetTextBkColor(RGB(247,247,255));
m_listcontrol.InsertColumn(0, _T("日期"), LVCFMT_LEFT, 80);//表头
m_listcontrol.InsertColumn(1, _T("时间"), LVCFMT_LEFT, 80);
m_listcontrol.InsertColumn(2, _T("流量"), LVCFMT_LEFT, 80);
m_listcontrol.InsertColumn(3, _T("探头1"), LVCFMT_LEFT, 80);
m_listcontrol.InsertColumn(4, _T("探头2"), LVCFMT_LEFT, 80);
m_listcontrol.InsertColumn(5, _T("探头3"), LVCFMT_LEFT, 80);
m_listcontrol.DeleteAllItems();//清除所有Item,这个很重要
(4)添加数据,之前要插一行,添加一行数据,
m_listcontrol.InsertItem(i,_T(""),0);//插入一行Item
for(int i=0;i < 4;i++)
for(int j = 0;j< 6;j++)
{
CString str = L“xx”;
m_listcontrol.SetItemText(i,j,str);
}