?
Solved

CListCtrl Row Height

Posted on 2006-05-01
6
Medium Priority
?
2,225 Views
Last Modified: 2013-11-20
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,
0
Comment
Question by:cophi
  • 5
6 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16583321
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16583329
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
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 2000 total points
ID: 16583364
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:cophi
ID: 16608994
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16612386
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16629556
Cophie so have you successfully implemented it ?

-MAHESH
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Loops Section Overview
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question