Removing space from images in CListCtrl

Posted on 1999-11-25
Medium Priority
Last Modified: 2013-11-20
I am able to remove an image from an item in a CListCtrl by doing :

listctrl->SetItem(row, 0, LVIF_IMAGE, NULL,-1, 0, 0, 0);

However, this only clears the space where the image/icon should have been.  The space that it takes up is not removed, so the text is still indented.  What can I do about this?
Question by:Claus
  • 3
  • 2
LVL 31

Expert Comment

ID: 2234328
Hi Claus,

seems that what you want is to just delete the list control item, so use this:

listctrl->DeleteItem( row );

hope that helps,


Author Comment

ID: 2234380
I tried it and it doesn't make any difference.  Perhaps I should provide some more information.  I am using the CListCtrl in report view and I also print text to the items with SetItemText().  So I want the text to be shown, but not the icon and certainly not the empty space where the icon should have been!
LVL 31

Expert Comment

ID: 2234427
Ok Claus, now I understand you.

To do this, only way I found out is to make your list control onwner drawn (i.e. select 'Ownder draw fixed' option in resource editor), derive a new class from CListCtrl and implement an owner draw function. An example on how to do this you can find at 'http://www.codeguru.com/listview/sel_row.shtml' (which also makes it possible to highlight a whole row). In this sample's DrawItem() function add following

CMyList::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
....// about 25 lines of code
// Get rectangles for drawing
CRect rcBounds, rcLabel, rcIcon;
GetItemRect(nItem, rcBounds, LVIR_BOUNDS);
GetItemRect(nItem, rcLabel, LVIR_LABEL);
GetItemRect(nItem, rcIcon, LVIR_ICON);
CRect rcCol( rcBounds );

// all above is existing code, just insert these two lines here
if ( lvi.iImage == -1 )
 rcLabel = rcBounds;

hope that helps,

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!


Author Comment

ID: 2235546
I think I have a problem there because my CListCtrl is already custom drawn.  It doesn't seem like DrawItem() is getting called at all ... anyway thanks for the help ...
LVL 31

Expert Comment

ID: 2235607
If it is already owner draw list control, do you have the source code of it's CListCtrl-derived class. Do you have permission to modify it?

Accepted Solution

Brian_HP earned 400 total points
ID: 2235724
With a custom drawn CListCtrl, you have to use code like the following :

    *pResult = CDRF_SKIPDEFAULT;

    CString sItem = GetItemText(iRow, iCol);
    CRect rc;

    GetCellRect(iRow, iCol, LVIR_BOUNDS, rc);

    // get the device context.
    CDC *pDC= CDC::FromHandle(lvcd->nmcd.hdc);

    // paint the text centered.
    pDC->DrawText(sItem, rc, DT_LEFT);


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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

593 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