Listview and Icons

  • Thread starter Thread starter Matthias Kwiedor
  • Start date Start date
M

Matthias Kwiedor

I have a Listview in Detail Mode. No i create lines with

ListViewItem lvwItem = new ListViewItem();
lvwItem = new System.Windows.Forms.ListViewItem(new System.Windows.Forms.ListViewItem.ListViewSubItem[] {
new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "text1", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)))),
new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "text2", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)))),
}, -1);
lvwItem.UseItemStyleForSubItems = false;

and add this to the listview

Now i want a icon displayd instead of "text2" - does anyone know how this works, i didn't find
something on the net!

I thought that i can change the lvwItem.subitem[1], before adding them to the listview,
but there is only a text and no image value.



Thanks




Matthias
 
Matthais,

In this case you will have to override the painting of the ListView and
paint the icon yourself. You will also have to create a mechanism to
associate an icon with a particular item in the ListView.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

Matthias Kwiedor said:
I have a Listview in Detail Mode. No i create lines with

ListViewItem lvwItem = new ListViewItem();
lvwItem = new System.Windows.Forms.ListViewItem(new
System.Windows.Forms.ListViewItem.ListViewSubItem[] {
new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "text1",
System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window,
new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)))),
new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "text2",
System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window,
new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)))),
}, -1);
lvwItem.UseItemStyleForSubItems = false;

and add this to the listview

Now i want a icon displayd instead of "text2" - does anyone know how this works, i didn't find
something on the net!

I thought that i can change the lvwItem.subitem[1], before adding them to the listview,
but there is only a text and no image value.



Thanks




Matthias
 
Matthais,

In this case you will have to override the painting of the
ListView and
paint the icon yourself. You will also have to create a mechanism to
associate an icon with a particular item in the ListView.

Hope this helps.

Thank you Nicholas,

i hope i will find some examples. But you lead me to a new way :)



Greets


Matthias
 
Back
Top