CListCtrl Row Height

How do I go about changing the Row Height if I DO NOT have an Owner Drawn CListCtrl.  If there is no easy way and its just better to derive the CListCtrl class, what do I call inside the CListCtrl::DrawItem, like the super??

Thanks,
cophiAsked:
Who is Participating?
 
mahesh1402Connect With a Mentor Commented:
and if you do not have Owner Drawn List Control then you may achieve this by changing height of font of List Control on your InitDialog using SetFont().

e.g
        m_pListFont = new CFont;
 
        LOGFONT logFont;
        memset(&logFont, 0, sizeof logFont);

        logFont.lfHeight = 15;

        lstrcpy(logFont.lfFaceName, _T("Courier New"));

        pListFont->CreateFontIndirect(&logFont);
        m_ListCtrl.SetFont(pListFont, TRUE);


http://support.microsoft.com/kb/q85518/

-MAHESH
0
 
mahesh1402Commented:
for your owner drawn list control :
your string is contained in MEASUREITEMSTRUCT.itemData .. you need to Add handler for WM_MEASUREITEM...so all you need to do is

void CMyListCtrl::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
{
     CClientDC dc(this);
     CMyInfo *pInfo = (CMyInfo *)lpMIS->itemData;

     int iLength = _tcslen(pInfo->tszLabel);
     TEXTMETRIC tm;
     dc.GetTextMetrics(&tm);

     // Here I arbitrarily say 34 characters can fit on a line
     lpMIS->itemHeight = iLength / 34 * tm.tmHeight;


}

http://www.codeguru.com/Cpp/controls/listview/advanced/article.php/c1013 <= Changing row height in owner drawn control
http://www.thecodeproject.com/listctrl/changerowheight.asp

-MAHESH
0
 
mahesh1402Commented:
Also you may refer 'MeasureItem for dynamic font changing in a list control'
http://www.codeguru.com/Cpp/controls/listview/miscellanious/article.php/c939 <==

-MAHESH
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
cophiAuthor Commented:
I'm getting an Assesition error when I try to override the OwnerDrawn List Control.  Why would this be.  

// ---------------------
// -- CListCtrlStyled --
// ---------------------
class CListCtrlStyled : public CListCtrl
{
public:
      // -- Construction --
      //
      CListCtrlStyled();
      virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);

....

void CListCtrlStyled::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
    TEXTMETRIC tm;
    HDC hDC = ::GetDC(NULL);
    CFont* pFont = GetFont();
    HFONT hFontOld = (HFONT)SelectObject(hDC, pFont->GetSafeHandle());
    GetTextMetrics(hDC, &tm);
    lpMeasureItemStruct->itemHeight = tm.tmHeight + tm.tmExternalLeading + 1;
    SelectObject(hDC, hFontOld);
    ::ReleaseDC(NULL, hDC);
}

void CListCtrlStyled::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
      CListCtrl::DrawItem(lpDrawItemStruct);
}
0
 
mahesh1402Commented:
I think you got solution for assert in your new question :
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21838607.html

-MAHESH
0
 
mahesh1402Commented:
Cophie so have you successfully implemented it ?

-MAHESH
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.