// MyListCtrl.cpp : 实现文件 // #include "stdafx.h" #include "XListCtrl.h" // CMyListCtrl IMPLEMENT_DYNAMIC(CXListCtrl, CMFCListCtrl) CXListCtrl::CXListCtrl() { } CXListCtrl::~CXListCtrl() { } BEGIN_MESSAGE_MAP(CXListCtrl, CMFCListCtrl) END_MESSAGE_MAP() /***************************************************************** **【函数名称】 PreSubclassWindow **【函数功能】 修正列表控件的相关扩展属性 **【参数】 **【返回值】 ****************************************************************/ void CXListCtrl::PreSubclassWindow() { SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES ); EnableMarkSortedColumn(); CMFCListCtrl::PreSubclassWindow(); } /***************************************************************** **【函数名称】 GetIndexByContent **【函数功能】 根据指定列的内容获取所在行的索引值 **【参数】 nColumn 要查找内容所在的列 lpszContent 要查找的内容 **【返回值】 -1 未找到 当前内容所在行的索引 ****************************************************************/ int CXListCtrl::GetIndexByContent(const UINT nColumn, LPCTSTR lpszContent) { for( int i=0; i < GetItemCount(); i++ ) { CString strTmp = GetItemText(i, nColumn); if(strTmp == lpszContent) return i; } // end for return -1; } /***************************************************************** **【函数名称】 RemoveSelection **【函数功能】 删除选中行 **【参数】 **【返回值】 ****************************************************************/ void CXListCtrl::RemoveSelection() { POSITION pos = this->GetFirstSelectedItemPosition(); while(pos != NULL) { int iIndex = this->GetNextSelectedItem(pos); this->DeleteItem(iIndex); pos = this->GetFirstSelectedItemPosition(); } // end while }