Solved

CListCtrl icons in subitems??

Posted on 2004-08-16
4
378 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

20 Experts available now in Live!

Get 1:1 Help Now