WinSDK方式清空ListView数据和表头

void ResetListViewData(HWND hDlg)
{
	int nCols=0;			//ListView列数
	HWND hWnd,hWndHeader;
	LVITEM lvItem;
	
	hWnd=GetDlgItem(hDlg,IDC_INFOLIST);
	
	//清空所有数据
	SendMessage(hWnd, LVM_DELETEALLITEMS, 0, 0);
	
	//获得ListView列数
	hWndHeader=(HWND)SendMessage(hWnd, LVM_GETHEADER, 0,0);
	nCols=SendMessage(hWndHeader, HDM_GETITEMCOUNT, 0, 0);
	
	//删除ListView所有列
	while(nCols)
	{
		SendMessage(hWnd,LVM_DELETECOLUMN,0,(LPARAM)&lvItem);
		nCols--;
	}
}

你可能感兴趣的:(ListView)