Dave's Brain

Browse - programming tips - mfc clistctrl getcolumncount

Date: 2008jul12
Platform: MFC
Language: C/C++

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);
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: