?
Solved

How can I change the height of the header in a ListView ?

Posted on 2007-11-26
5
Medium Priority
?
1,253 Views
Last Modified: 2013-11-20
Hello,

is there an easy way to adjust the Header's Height for ListView?

Thanks
Best regards,
Thomas

0
Comment
Question by:tsp2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20351046
there is not an easy way, you have to do owner-draw.
0
 

Author Comment

by:tsp2002
ID: 20351776
I now how to do a owner-draw...changed the color of the listview text before.
But how do I get the height and width?
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 2000 total points
ID: 20356195
Here's an approach that might work for you:
1) Choose a font size with height approximately what you want the header to be, then set the header font to it - something like:

// one time initialization
m_sizingFont.CreatePointFont(180, "MS Sans Serif");
m_normalFont.CreatePointFont(80, "MS Sans Serif");

CHeaderCtrl * pHdrCtrl = m_listCtrl.GetHeaderCtrl();

pHdrCtrl->SetFont(&m_sizingFont);

2) Make each header item owner draw.
// for each column do something like the following:
HD_ITEM curItem;

pHdrCtrl->GetItem(column, &curItem);
curItem.mask = HDI_FORMAT;
curItem.fmt = HDF_OWNERDRAW;

pHdrCtrl->SetItem(column, &curItem);

3) Finally, Draw header items, which may be trivial or complex depending on your applkication. The following snippet merely uses whatever was set in the each header item, which you have to do anyway.

void MyListCtrl::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT pdis )
{
ASSERT(pdis->CtlType == ODT_HEADER);

CDC * pdc = CDC::FromHandle(pdis->hDC);
CFont * pOldFont = pdc->SelectObject(&m_normalFont);

LVCOLUMN col;
char buff[64];

col.mask = LVCF_IMAGE | LVCF_TEXT;
col.pszText = buff;
col.cchTextMax = sizeof(buff);

GetColumn(pdis->itemID, &col);

CRect rect(pdis->rcItem);
rect.left += 2;
int height = pdc->DrawText(buff, rect, DT_SINGLELINE | DT_LEFT | DT_TOP | DT_END_ELLIPSIS);

rect.top += height;
m_headerImageList.Draw(pdc, pdis->iImage, rect.TopLeft(), ILD_NORMAL);

pdc->SelectObject(pOldFont);
}


Hope this helps
-MAHESH
0
 

Author Comment

by:tsp2002
ID: 20356456
Hi Mahesh,
thanks for the code...let you know shortly
Best regards
Thomas
0
 

Author Comment

by:tsp2002
ID: 20357483
Hi Mahesh,
I can work from here.
Thank you.
Here are your 500 points.
Best regards,
Thomas
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

650 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