若XXView继承的是CListCtrl类,那么直接调用函数CListCtrl &m_listctrl = GetCtrl();即可获取视图类中ListCtrl的指针,插入数据通过m_listctrl操作.
若是CListCtrl控件的话,则需要自己定义控件变量.
我看很多朋友是定义的lvcolumn结构体进行数据插入,因为这个功能较多,不过我觉得比较麻烦.
所以我喜欢用下面的方法:
int nIndex = m_listctrl.InsertColumn(m_listctrl.GetItemCount(), str);
m_listctrl.SetItemText(nIndex, 0, str1);
m_listctrl.SetItemText(nIndex, 1, str2);
m_listctrl.SetItemText(nIndex, 2, str3);
…比较方便,不过插入数据类型是有限制的.
另外将CListCtrl在代码中设置为Report形式需要在PreCreateWindow里加入:
cs.style |= LVS_REPORT | LVS_SINGLESEL;
cs.dwExStyle = LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT;