chongpeng
asked on
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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
VinExpert,
looks like you also didn't get "subitem "?
looks like you also didn't get "subitem "?
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
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
Set extended style LVS_EX_SUBITEMIMAGES.
Vicky
Vicky
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.
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.
This style is only available in version 4.70 and later of comctls.
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.
Even if he does not have it ( which does not seem to be possible) he can download it from microsoft site.
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
The newer versions of Common Controls are freely downloadable and can be distributed. For this purpose, MS provides royalty free distributables.
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_iIn dex ++)
{
lvcol.pszText = "One";
m_ctrlList.InsertColumn(l_ iIndex, &lvcol);
}
//Set the extended styles
ListView_SetExtendedListVi ewStyle(m_ ctrlList,L VS_EX_FULL ROWSELECT | 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(&lvi tem);
lvitem.iSubItem = 1;
m_ctrlList.InsertItem(&lvi tem);
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
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_iIn
{
lvcol.pszText = "One";
m_ctrlList.InsertColumn(l_
}
//Set the extended styles
ListView_SetExtendedListVi
//Get the Icons into Imagelist
m_Images.Create(16,16,0,0,
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
//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(&lvi
lvitem.iSubItem = 1;
m_ctrlList.InsertItem(&lvi
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
Sorry, Sorry, Sorry, it was supposed to be an comment.
VinExpert