Dave's Brain

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);
	}

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.