• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • Last Modified:

CListCtrl icons in subitems??

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
Jedimaster
Asked:
Jedimaster
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
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
 
itsmeandnobodyelseCommented:
>> 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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now