Image in CListCtrl subitem.

I am using Visual C++ 6.0. How to display icon in subitem of CListCtrl subitem, besides those of 1st column ?
chongpengAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
Hi,

While inserting the items, use LV_ITEM structure and put the parameters
specify item and subitem
state = LVIF_IMAGE
state and stateMask   = LVIS_STATEIMAGEMASK  ;
iImage   = index of the icon in the CImageList

For that U have to create the image list and Add the icons to it.
Then specify the icon indexes to it.

Hope it helps.
VinExpert
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vinayak KumbarSr Program ManagerCommented:
Hi,

Sorry, Sorry, Sorry, it was supposed to be an comment.

VinExpert
0
MichaelSCommented:
VinExpert,
looks like you also didn't get "subitem "?
0
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Vinayak KumbarSr Program ManagerCommented:
Hi MichaelS,

I have already told that i never wanted to put it as an answer. I was directing him in that way as I dont have vc 6.0 now. And I think subitem functionalities are supported in vc++6.0.

Cheers,
VinExpert
0
V_BapatCommented:
Set extended style LVS_EX_SUBITEMIMAGES.

Vicky
0
V_BapatCommented:
I am assuming that you have set the extended style and added items and subitems. In the following code snippet, I am adding images to 2nd and 3rd columns of all the three rows.

      LV_ITEM lvi;
      for(i = 0; i < 3; i++)
      {
            for(int j = 1; j <=2; j++)
            {
                  lvi.iItem = i;
                  lvi.iSubItem = j;
                  m_listctrl.GetItem(&lvi);
                  lvi.mask = LVIF_IMAGE;
                  lvi.iImage = i;
                  m_listctrl.SetItem(&lvi);
            }
      }

Try it out.
0
MichaelSCommented:
This style is only available in version 4.70 and later of comctls.
0
V_BapatCommented:
You are correct, but Chongpeng has mentioned that he is using VC++ 6.0. So it won't be a problem.
Even if he does not have it ( which does not seem to be possible) he can download it from microsoft site.
0
MichaelSCommented:
It's not a problem to have it but if Chongpeng will install his app to some win95 pc this approach may couse a porblem
0
V_BapatCommented:
The newer versions of Common Controls are freely downloadable and can be distributed. For this purpose, MS provides royalty free distributables.
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

Here is the working code using VC 6.0
here m_ctrlList is the list control variable associated with the list control. And m_Images is the CImageList object declared in dialogs .h file.

              //Give the titles
      CStringArray l_saTitle;
      l_saTitle.Add("Column1");
      l_saTitle.Add("Column2");
      l_saTitle.Add("Column3");
      
      //Start Inserting the columns
      LV_COLUMN lvcol;
      lvcol.mask = LVCF_IMAGE ;
      lvcol.fmt = LVCFMT_IMAGE;
      
      for(int l_iIndex = 0;l_iIndex <l_saTitle.GetSize();l_iIndex ++)
      {
            lvcol.pszText = "One";            
            m_ctrlList.InsertColumn(l_iIndex, &lvcol);
      }

      //Set the extended styles
      ListView_SetExtendedListViewStyle(m_ctrlList,LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE | LVS_EX_SUBITEMIMAGES);

      //Get the Icons into Imagelist
      m_Images.Create(16,16,0,0,2);
      HICON icon = LoadIcon(0, IDI_QUESTION);
      m_Images.Add(icon);
      icon = LoadIcon(0, IDI_WINLOGO );
      m_Images.Add(icon);

      //Set that image list to ListCtrl
      m_ctrlList.SetImageList(&m_Images, LVSIL_SMALL);

      //Start Inserting the items
      LV_ITEM lvitem;
      lvitem.iItem = 0;
      lvitem.iSubItem = 0;
      lvitem.pszText = "er";  
      lvitem.mask = LVIF_IMAGE;
      lvitem.state =  LVIS_STATEIMAGEMASK ;
      lvitem.stateMask = LVIS_STATEIMAGEMASK ;
      lvitem.iImage = 1;
      m_ctrlList.InsertItem(&lvitem);      
      lvitem.iSubItem = 1;
      m_ctrlList.InsertItem(&lvitem);      
      m_ctrlList.SetItem(&lvitem);

I think v_Bapat also tried to say same thing(u can get from his comments). Hope this gives u a clear code idea to insert the icons into the subitems.

VinExpert
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.