How do you get the column count of a list control?
Printable View
How do you get the column count of a list control?
For MSVC 6:
// How many columns are there?
int MyListCtrl::GetColumnCount() const
{
// One of the few examples of when this cast is okay. (Microsoft forgot
// to supply a const CListCtrl::GetHeaderCtrl() - doh!)
CHeaderCtrl* pHeader = const_cast<MyListCtrl*> (this)->GetHeaderCtrl();
ASSERT_VALID(pHeader);
return pHeader ? pHeader->GetItemCount() : -1;
}
For MSVC5, this is the best we can do:
// Does the sent column exist?
BOOL MyListCtrl::IsColumn(int nCol) const
{
_ASSERTE(0 <= nCol);
LV_COLUMN lvc;
::ZeroMemory(&lvc, sizeof(lvc));
lvc.mask = LVCF_WIDTH;
return -1 < nCol && GetColumn(nCol, &lvc);
}
LA Leonard - http://www.DefinitiveSolutions.com
I thank you for your response, but I am still using vc4 for the meantime. I hope you have an example for this version?
The one for MSVC5 should work for MSVC4, I think...
LA Leonard - http://www.DefinitiveSolutions.com
I tried it and it did the trick. Thanks!!