Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CListCtrl icons in subitems??

Posted on 2004-08-16
4
Medium Priority
?
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 400 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 45

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

609 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