Discussion:
List Control Images
(too old to reply)
saywhat
2006-04-01 19:21:06 UTC
Permalink
I have looked all around, and still can't see why this doesn't work.

I want to simply insert an image in a column of my list control. I can't
seem to get my image past the first subitem, even if I use the LVITEM
structure. It will display the images denoted fromthe image list, bu only
in the first column.

Also when I use SetImageList for my control, The first image ion the list
always appears before any text I insert in the first column. If I comment
out the SetImageList function, no image appears (duh).

Any ideas....TIA

b
Tom Serface
2006-04-01 22:32:39 UTC
Permalink
This article describes a CListCtrl extension that allows you to have images
in subitems. Maybe you can learn something from the code here:

https://secure.codeproject.com/listctrl/ReportControl.asp

Specifically, in the Q&A at the bottom a user asked the same question and
the response was:

used these statements..CListCtrl m_ListFirst;

DWORD dwStyle =m_ListFirst.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES;
m_ListFirst.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);

and then....

m_ListFirst.SetItem(nItem, nSubItem, LVIF_IMAGE, NULL, nImage, 0, 0, 0);

This class extension all supports LVS_EX_SUBITEMIMAGES:

http://www.codeguru.com/Cpp/controls/listview/advanced/article.php/c4179/

Tom
Post by saywhat
I have looked all around, and still can't see why this doesn't work.
I want to simply insert an image in a column of my list control. I can't
seem to get my image past the first subitem, even if I use the LVITEM
structure. It will display the images denoted fromthe image list, bu only
in the first column.
Also when I use SetImageList for my control, The first image ion the list
always appears before any text I insert in the first column. If I comment
out the SetImageList function, no image appears (duh).
Any ideas....TIA
b
saywhat
2006-04-01 23:32:00 UTC
Permalink
This code doesn't work for me... arrgh!

I have a variable of the image list in my view class, as well as one of the
list control.

I created the control, even got a bitmap in the header :-), then called
SetImageList.

I then used

SetItem(nItem, nSubItem, LVIF_IMAGE, NULL, nImage, 0, 0, 0);

passsing it the values of the item and subitem index as well as the position
in the imagelist i want to use.

I get the results described below... I set the extended styles for subitem
bitmaps too, btw.

What gives?
Post by Tom Serface
This article describes a CListCtrl extension that allows you to have
https://secure.codeproject.com/listctrl/ReportControl.asp
Specifically, in the Q&A at the bottom a user asked the same question and
used these statements..CListCtrl m_ListFirst;
DWORD dwStyle =m_ListFirst.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES;
m_ListFirst.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);
and then....
m_ListFirst.SetItem(nItem, nSubItem, LVIF_IMAGE, NULL, nImage, 0, 0, 0);
http://www.codeguru.com/Cpp/controls/listview/advanced/article.php/c4179/
Tom
Post by saywhat
I have looked all around, and still can't see why this doesn't work.
I want to simply insert an image in a column of my list control. I can't
seem to get my image past the first subitem, even if I use the LVITEM
structure. It will display the images denoted fromthe image list, bu
only in the first column.
Also when I use SetImageList for my control, The first image ion the list
always appears before any text I insert in the first column. If I
comment out the SetImageList function, no image appears (duh).
Any ideas....TIA
b
saywhat
2006-04-02 16:54:16 UTC
Permalink
Boy this is really vexing me. PS thanks Tom for your help...

I've pored through the docs again, to no avail. I have a feeling there's
something I'm missing somewhere. I know the list class is created properly.
Just want to slip a bitmap froma an imagelist into a column.

The imagelist is valid because I used it in the header control, voila, there
it is, I can point to eash of the 4 images in the list without a problem.

Again TIA,.,,,

Bruce
Post by Tom Serface
This article describes a CListCtrl extension that allows you to have
https://secure.codeproject.com/listctrl/ReportControl.asp
Specifically, in the Q&A at the bottom a user asked the same question and
used these statements..CListCtrl m_ListFirst;
DWORD dwStyle =m_ListFirst.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES;
m_ListFirst.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);
and then....
m_ListFirst.SetItem(nItem, nSubItem, LVIF_IMAGE, NULL, nImage, 0, 0, 0);
http://www.codeguru.com/Cpp/controls/listview/advanced/article.php/c4179/
Tom
Post by saywhat
I have looked all around, and still can't see why this doesn't work.
I want to simply insert an image in a column of my list control. I can't
seem to get my image past the first subitem, even if I use the LVITEM
structure. It will display the images denoted fromthe image list, bu
only in the first column.
Also when I use SetImageList for my control, The first image ion the list
always appears before any text I insert in the first column. If I
comment out the SetImageList function, no image appears (duh).
Any ideas....TIA
b
Tom Serface
2006-04-03 14:59:52 UTC
Permalink
It's difficult to say without seeing your actual code. Are you setting the
style to allow subitem images in the extended styles. Do you have the
latest version of Internet Explorer (above 4.1) that supports this feature?

Tom
Post by saywhat
Boy this is really vexing me. PS thanks Tom for your help...
I've pored through the docs again, to no avail. I have a feeling there's
something I'm missing somewhere. I know the list class is created properly.
Just want to slip a bitmap froma an imagelist into a column.
The imagelist is valid because I used it in the header control, voila, there
it is, I can point to eash of the 4 images in the list without a problem.
Again TIA,.,,,
Bruce
Post by Tom Serface
This article describes a CListCtrl extension that allows you to have
https://secure.codeproject.com/listctrl/ReportControl.asp
Specifically, in the Q&A at the bottom a user asked the same question and
used these statements..CListCtrl m_ListFirst;
DWORD dwStyle =m_ListFirst.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES;
m_ListFirst.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);
and then....
m_ListFirst.SetItem(nItem, nSubItem, LVIF_IMAGE, NULL, nImage, 0, 0, 0);
http://www.codeguru.com/Cpp/controls/listview/advanced/article.php/c4179/
Tom
Post by saywhat
I have looked all around, and still can't see why this doesn't work.
I want to simply insert an image in a column of my list control. I can't
seem to get my image past the first subitem, even if I use the LVITEM
structure. It will display the images denoted fromthe image list, bu
only in the first column.
Also when I use SetImageList for my control, The first image ion the list
always appears before any text I insert in the first column. If I
comment out the SetImageList function, no image appears (duh).
Any ideas....TIA
b
saywhat
2006-04-03 16:46:48 UTC
Permalink
Yes and yes.

I set LVS_EX_SUBITEMIMAGES

I attached the image list to the list ctrl.

I then used SetItem as indicated.

Both the list ctrl and the image were added to my view class as variables.

This is holding up my whole project. I will try and post my exact code here
later.

Thanks for your efforts!!!!

b
Post by Tom Serface
It's difficult to say without seeing your actual code. Are you setting
the style to allow subitem images in the extended styles. Do you have the
latest version of Internet Explorer (above 4.1) that supports this feature?
Tom
Post by saywhat
Boy this is really vexing me. PS thanks Tom for your help...
I've pored through the docs again, to no avail. I have a feeling there's
something I'm missing somewhere. I know the list class is created properly.
Just want to slip a bitmap froma an imagelist into a column.
The imagelist is valid because I used it in the header control, voila, there
it is, I can point to eash of the 4 images in the list without a problem.
Again TIA,.,,,
Bruce
Post by Tom Serface
This article describes a CListCtrl extension that allows you to have
https://secure.codeproject.com/listctrl/ReportControl.asp
Specifically, in the Q&A at the bottom a user asked the same question and
used these statements..CListCtrl m_ListFirst;
DWORD dwStyle
=m_ListFirst.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES;
m_ListFirst.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);
and then....
m_ListFirst.SetItem(nItem, nSubItem, LVIF_IMAGE, NULL, nImage, 0, 0, 0);
http://www.codeguru.com/Cpp/controls/listview/advanced/article.php/c4179/
Tom
Post by saywhat
I have looked all around, and still can't see why this doesn't work.
I want to simply insert an image in a column of my list control. I can't
seem to get my image past the first subitem, even if I use the LVITEM
structure. It will display the images denoted fromthe image list, bu
only in the first column.
Also when I use SetImageList for my control, The first image ion the list
always appears before any text I insert in the first column. If I
comment out the SetImageList function, no image appears (duh).
Any ideas....TIA
b
Tom Serface
2006-04-03 18:28:37 UTC
Permalink
Thanks I'll look and I'm sure others will as well. Hopefully, it's
something simple that you're just overlooking.

Tom
Post by saywhat
Yes and yes.
I set LVS_EX_SUBITEMIMAGES
I attached the image list to the list ctrl.
I then used SetItem as indicated.
Both the list ctrl and the image were added to my view class as variables.
This is holding up my whole project. I will try and post my exact code
here later.
Thanks for your efforts!!!!
b
Post by Tom Serface
It's difficult to say without seeing your actual code. Are you setting
the style to allow subitem images in the extended styles. Do you have
the latest version of Internet Explorer (above 4.1) that supports this
feature?
Tom
Post by saywhat
Boy this is really vexing me. PS thanks Tom for your help...
I've pored through the docs again, to no avail. I have a feeling there's
something I'm missing somewhere. I know the list class is created properly.
Just want to slip a bitmap froma an imagelist into a column.
The imagelist is valid because I used it in the header control, voila, there
it is, I can point to eash of the 4 images in the list without a problem.
Again TIA,.,,,
Bruce
Post by Tom Serface
This article describes a CListCtrl extension that allows you to have
https://secure.codeproject.com/listctrl/ReportControl.asp
Specifically, in the Q&A at the bottom a user asked the same question and
used these statements..CListCtrl m_ListFirst;
DWORD dwStyle
=m_ListFirst.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES;
m_ListFirst.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);
and then....
m_ListFirst.SetItem(nItem, nSubItem, LVIF_IMAGE, NULL, nImage, 0, 0, 0);
http://www.codeguru.com/Cpp/controls/listview/advanced/article.php/c4179/
Tom
Post by saywhat
I have looked all around, and still can't see why this doesn't work.
I want to simply insert an image in a column of my list control. I can't
seem to get my image past the first subitem, even if I use the LVITEM
structure. It will display the images denoted fromthe image list, bu
only in the first column.
Also when I use SetImageList for my control, The first image ion the list
always appears before any text I insert in the first column. If I
comment out the SetImageList function, no image appears (duh).
Any ideas....TIA
b
saywhat
2006-04-03 22:33:07 UTC
Permalink
Okay, here goes - this is on the OnInitialUpdate func. of my view class
(form view)
Excuse my shoddy code, when I hit this 'speed bump' I didn't clean it up
before I could get SetItem to work, which it still doesn't.

Again I really appreciate you all having a look!

I added variables to view class - CListCtrl List, CImageList ilist....
////////////////////////////////////////////////////////////////////////////////////////////////////////
CRect rect;
CRect lrect;
GetWindowRect(rect);
List.Create(WS_CHILD|WS_VISIBLE|LVS_OWNERDRAWFIXED|LVS_REPORT,CRect(10,30,(rect.Width()-10),(rect.Height()-50)),this,0);
ilist.Create(IDB_ILIST1,6,2,RGB(255,0,255));

List.SetImageList(&ilist,LVSIL_SMALL);
List.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES );

List.GetWindowRect(lrect);
int w = lrect.Width();
List.InsertColumn(0,"Sender",0,int(w*.2));
List.InsertColumn(1,"Subject",0,int(w*.4));
List.InsertColumn(2,"Date",0,int(w*.2));
List.InsertColumn(3,"Size",0,int(w*.05));
List.InsertColumn(4,NULL,0,20);
///////////////////////
CHeaderCtrl* pHead = List.GetHeaderCtrl();
pHead->SetImageList(&ilist);

HDITEM hdi;
pHead->GetItem(4,&hdi);
hdi.mask |=HDI_IMAGE|HDI_FORMAT;
hdi.fmt |=HDF_IMAGE|HDF_CENTER;
hdi.fmt &=~HDF_STRING;
hdi.iImage=0;
pHead->SetItem( 4, &hdi); //////////////////////////////<---- This works
List.SetItem(0,0,LVIF_IMAGE, NULL, 1, 0, 0, 0);////<----This doesn't :-(
///////////////////////////////////////////////////////


I tried to see if SetItemText works - it doesn't either. Very perplexing.
Thanks a million

b
Post by Tom Serface
Thanks I'll look and I'm sure others will as well. Hopefully, it's
something simple that you're just overlooking.
Tom
Post by saywhat
Yes and yes.
I set LVS_EX_SUBITEMIMAGES
I attached the image list to the list ctrl.
I then used SetItem as indicated.
Both the list ctrl and the image were added to my view class as variables.
This is holding up my whole project. I will try and post my exact code
here later.
Thanks for your efforts!!!!
b
Post by Tom Serface
It's difficult to say without seeing your actual code. Are you setting
the style to allow subitem images in the extended styles. Do you have
the latest version of Internet Explorer (above 4.1) that supports this
feature?
Tom
Post by saywhat
Boy this is really vexing me. PS thanks Tom for your help...
I've pored through the docs again, to no avail. I have a feeling there's
something I'm missing somewhere. I know the list class is created properly.
Just want to slip a bitmap froma an imagelist into a column.
The imagelist is valid because I used it in the header control, voila, there
it is, I can point to eash of the 4 images in the list without a problem.
Again TIA,.,,,
Bruce
Post by Tom Serface
This article describes a CListCtrl extension that allows you to have
https://secure.codeproject.com/listctrl/ReportControl.asp
Specifically, in the Q&A at the bottom a user asked the same question and
used these statements..CListCtrl m_ListFirst;
DWORD dwStyle
=m_ListFirst.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES;
m_ListFirst.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);
and then....
m_ListFirst.SetItem(nItem, nSubItem, LVIF_IMAGE, NULL, nImage, 0, 0, 0);
http://www.codeguru.com/Cpp/controls/listview/advanced/article.php/c4179/
Tom
Post by saywhat
I have looked all around, and still can't see why this doesn't work.
I want to simply insert an image in a column of my list control. I can't
seem to get my image past the first subitem, even if I use the LVITEM
structure. It will display the images denoted fromthe image list, bu
only in the first column.
Also when I use SetImageList for my control, The first image ion the list
always appears before any text I insert in the first column. If I
comment out the SetImageList function, no image appears (duh).
Any ideas....TIA
b
Continue reading on narkive:
Loading...