c++:listcontrol 的用法 ListControl 列表控件可以看作是功能增强的ListBox,它提供了四种风格,而且可以同时显示一列的多中属性值。MFC 中使用CListCtrl 类来封装列表控件的各种操作。通过调用 BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID ); 创建一个窗口,dwStyle 中可以使用以下一些列表控件的专用风格: LVS_ICON ,LVS_SMALLICON ,LVS_LIST, LVS_REPORT 这四种风格决定控件的外观,同时只可以选择其中一种,分别对应:大图标显示,小图标显示,列表显示,详细报表显示 ..。 LVS_EDITLABELS 结点的显示字符可以被编辑,对于报表风格来讲可编辑的只为第一列。 LVS_SHOWSELALWAYS 在失去焦点时也显示当前选中的结点 LVS_SINGLESEL 同时只能选中列表中一项 首先你需要设置列表控件所使用的ImageList,如果你使用大图标显示风格,你就需要以如下形式调用: CImageList* SetImageList( CImageList* pImageList, LVSIL_NORMAL); 如果使用其它三种风格显示而不想显示图标你可以不进行任何设置,否则需要以如下形式调用: CImageList* SetImageList( CImageList* pImageList, LVSIL_SMALL); int InsertItem( int nItem, LPCTSTR lpszItem ); 插入行 nItem:指明插入位置 lpszItem:为显示字符。 除 LVS_REPORT 风格外其他三种风格都只需要直接调用InsertItem 就可以了,但如果使用报表风格就必须先设置列表控件中的列信息。 int InsertColumn( int nCol, LPCTSTR lpszColumnHeading, int nFormat , int nWidth, int nSubItem);插入列 iCol:为列的位置,从零开始 lpszColumnHeading:为显示的列名 nFormat:为显示对齐方式 nWidth:为显示宽度 nSubItem:为分配给该列的列索引。 BOOL SetItemText( int nItem, int nSubItem, LPTSTR lpszText );设置每列的显示字符 nItem:为行位置 nSubItem:为列位置 lpszText:为显示字符 下面的代码演示了如何设置多列并插入数据: m_list.SetImageList(&m_listSmall,LVSIL_SMALL);//设置 ImageList m_list.InsertColumn(0,"Col 1",LVCFMT_LEFT,300,0);//设置列 m_list.InsertColumn(1,"Col 2",LVCFMT_LEFT,300,1); m_list.InsertColumn(2,"Col 3",LVCFMT_LEFT,300,2); m_list.InsertItem(0,"Item 1_1");//插入行 m_list.SetItemText(0,1,"Item 1_2");//设置该行的不同列的...