Listview and Icons

  • Thread starter Matthias Kwiedor
  • 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
 
N

Nicholas Paldino [.NET/C# MVP]

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
 
M

Matthias Kwiedor

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top