Solved

CListCtrl icons in subitems??

Posted on 2004-08-16
4
363 Views
Last Modified: 2013-11-20
I am trying to use a CListCtrl and I need one of my subitems to have an icon that changes based on dynamic data.  But for some reason I can only get it to show an icon in the far left item (assuming I don't drag a column).  As well as the icon does not change when I set the item using a different image index.  Anyone have any ideas about what I am doing wrong??  Has anyone done something simiar??  

Code snippits below:

  I have a dialog with a CListCtrl on it and here is how I am setting it up:

================================================
  HICON hIcon;
  hIcon = m_pMain->LoadIcon(IDI_ICO_UP);
  m_UpDownIcons.Add(hIcon);
  hIcon = m_pMain->LoadIcon(IDI_ICO_DOWN);
  m_UpDownIcons.Add(hIcon);

  m_lstFavMonitor.SetExtendedStyle(LVS_EX_HEADERDRAGDROP|LVS_EX_SUBITEMIMAGES|LVS_EX_ONECLICKACTIVATE);

  m_lstFavMonitor.SetImageList(&m_UpDownIcons,LVSIL_SMALL);

//Insert columns here...
================================================

I am inserting an item into the list like this:

================================================
  //insert our new item
  m_lstFavMonitor.InsertItem(0,(LPCSTR)pSymbol);
================================================

every time the data changes I update the subitems like this:

================================================
    if((pUpdate->GetLastPrice())<(pUpdate->GetOpenPrice()))
    {
      bool bret = m_lstFavMonitor.SetItem(iItem,4,LVIF_TEXT,newString,0,0,0,NULL);
      m_lstFavMonitor.SetItemTxtColor(iItem,4,RGB(184,1,29));
      m_lstFavMonitor.SetItemStyle(iItem,4,LIS_TXTCOLOR);
    }
    else if((pUpdate->GetLastPrice())>(pUpdate->GetOpenPrice()))
    {
       bool bret = m_lstFavMonitor.SetItem(iItem,4,LVIF_TEXT,newString,1,0,0,NULL);
      m_lstFavMonitor.SetItemTxtColor(iItem,4,RGB(20,183,2));
      m_lstFavMonitor.SetItemStyle(iItem,4,LIS_TXTCOLOR);
    }
    else
    {
      m_lstFavMonitor.SetItem(iItem,4,LVIF_TEXT,newString,2,0,0,NULL);
      m_lstFavMonitor.SetItemTxtColor(iItem,4,RGB(0,0,0));
      m_lstFavMonitor.SetItemStyle(iItem,4,LIS_TXTCOLOR);
    }

================================================


I am using WinXP SP1 and VS.NET 2003.

Thanks,

Jedimaster
0
Comment
Question by:Jedimaster
4 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 200 total points
ID: 11813288
You cannot use icons for second or third column with standard CListCtrl, but you can use any derived classes of codeproject:
http://www.codeproject.com/listctrl/
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11814503
>> As well as the icon does not change when I set the item using a different image index.  

To change the icon of a Listcontrol you have to set  the iImage argument and set LVIF_IMAGE when calling SetItem:
       
        m_lstFavMonitor.SetItem(iItem,4,LVIF_TEXT|LVIF_IMAGE,newString,1,0,0,NULL);

(as you did load only 2 icons, you may have iImage == 0 or iImage == 1 BUT NOT iImage == 2 (????)

>> But for some reason I can only get it to show an icon in the far left item

Yes, standard CListCtrl  has one icon per row (and nozt per item).

Regards, Alex



0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11818220
Owner draw / custom draw.  There you have to display the contents of the row/col so you can display what you want.  (It's not that difficult to do)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
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…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now