CListView和CListCtrl

来源:互联网 发布:lua for windows 64位 编辑:程序博客网 时间:2024/06/06 19:14
将CListCtrl绑定到CListView 使用GetListCtrl(),*CListCtrl=&GetListCtrl();。

要想显示模式和Access数据库那样的,要重载PreCreateWindow,在BOOL CListView::PreCreateWindow(CREATESTRUCT& cs)里添加cs.style |= LVS_REPORT; 。

设置显示样式,调用DWORD SetExtendedStyle( DWORD dwNewStyle );

添加列,调用int InsertColumn (int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1)。

其中,列宽可以在以后调用BOOL SetColumnWidth (int nCol, int cx);函数重新设定。

添加数据时先调用int InsertItem(int nItem, LPCTSTR lpszItem);添加一行和其第一列数据,再调用BOOL SetItemText (int nItem, int nSubItem, LPCTSTR lpszText);添加一行中其他列的数据。

 

如果设置了LVS_EX_CHECKBOXES属性,则可以用
 BOOL GetCheck( int nItem ) const;
来得到某一行是否Checked。

可以先用下面的语句来删除以前的东西:
 for(int k=2;k>=0;k--) //注意要从后往前删,否则出错
  m_ListCtrl.DeleteColumn(k);
 m_ListCtrl.DeleteAllItems();