Solved

CListCtrl icons in subitems??

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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