How to change the color of a subitem of a listview item?

K

Kuehiong Tu

Is there any way to change only the ForeColor and
BackColor of a subitem of a listview item? That means
if the listview is displayed in detailed mode, only one
field of a listview item has a different color instead of
the whole row.
..
 
J

Jerry Ham

Here's a quick VB.Net sample...

Dim lvi As ListViewItem
Dim f As Font
f = New Font(ListView1.Font, FontStyle.Bold)
Dim bgc As System.Drawing.Color
bgc = ListView1.BackColor
Dim lColor As System.Drawing.Color
lColor = System.Drawing.Color.Blue
Dim uf As New Font(f, FontStyle.Underline)
lvi = ListView1.Items.Add("Test")
lvi.UseItemStyleForSubItems = False
lvi.ForeColor = lColor
lvi.Font = uf
lvi.SubItems.Add("Different Color")
lvi.SubItems.Add("Same Color")
lvi.SubItems.Add("Another", System.Drawing.Color.Red, bgc, f)
lvi.SubItems.Add("Blue", System.Drawing.Color.DodgerBlue, bgc, f)

Jerry
 

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