Removing space from images in CListCtrl

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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Claus,

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

listctrl->DeleteItem( row );

hope that helps,

ClausAuthor Commented:
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!
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 '' (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,

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

ClausAuthor Commented:
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 ...
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?
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);


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.