删除CListCtrl中具有某一相同数据的所有行

删除CListCtrl中具有某一相同数据的所有行

==================================

本文原创,转载请注明出处:http://blog.csdn.net/wlsgzl/article/details/42103815

参考资料:MSDN

==================================

void CMainFrame::DeleteInListCtrl(CString strDel,CListCtrl* pListCtrl)
{
	LVFINDINFO stFindInfo;
	stFindInfo.flags = LVFI_PARTIAL|LVFI_STRING;
	stFindInfo.psz = strDel;

	int nIndex;
	while ((nIndex = pListCtrl->FindItem(&stFindInfo)) != -1)
	{
		pListCtrl->DeleteItem(nIndex);
	}
}


这里有一个限制,MSDN原文:

LVFI_PARTIAL Checks to see if the item text begins with the string pointed to by the psz member. This value implies use of LVFI_STRING.

也就是说,被查找的字符串必须是在控件中的第一列。

所以,使用这个函数可能需要调整控件中数据的填充顺序。

原文地址:https://www.cnblogs.com/wlsandwho/p/4202067.html