Click to See Complete Forum and Search --> : Columns in list control


delbert Harry
April 29th, 1999, 02:08 PM
How do you get the column count of a list control?

LALeonard
April 29th, 1999, 04:17 PM
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

delbert Harry
April 29th, 1999, 04:45 PM
I thank you for your response, but I am still using vc4 for the meantime. I hope you have an example for this version?

LALeonard
April 29th, 1999, 05:21 PM
The one for MSVC5 should work for MSVC4, I think...

LA Leonard - http://www.DefinitiveSolutions.com

delbert Harry
April 30th, 1999, 08:39 AM
I tried it and it did the trick. Thanks!!