Browse - Programming Tips - How can I find the number of columns in a CListCtrl ?

Date: 2008jul12
framework: MFC
Language: C/C++
Code: indented
OS: Windows

Q.  How can I find the number of columns in a CListCtrl ?

A.  Use this function:

	int GetColumnCount(const CListCtrl *pListCtrl)
	{
		CHeaderCtrl* pHeader;
		
		if (pListCtrl == NULL) return 0;
		if ((pHeader = const_cast<MyListCtrl*>(pListCtrl)->GetHeaderCtrl()) == NULL) return 0;
		return pHeader->GetItemCount();
	}
	
	void ExampleUse()
	{
		CListCtrl	ctrl;
		int		n;
	
		n = GetColumnCount(&ctrl);
		printf("There are %d columns\n", n);
	}