Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing font colour in ListView, VB2005

Status
Not open for further replies.

soldierB

Technical User
Dec 11, 2005
37
GB
Hi Guys,

Im trying out the ListView In VB2005

I want to change the font colour of the data being loaded depending on the value of one of the fields in the database.

I did this in VB6 but am not quite getting it here, can some one point me in the right direction.

Here is what Im trying just now

Code:
'---Populate the ListView

            Dim dRow As DataRow
            For Each dRow In objDataSet.Tables(0).Rows
                Dim itemX As ListViewItem = New ListViewItem(dRow(1).ToString & "" & dRow(2).ToString)
                itemX.SubItems.Add(dRow(0))

                If dRow(1).ToString = "" Then
                    itemX.SubItems.Item(1).ForeColor = Color.Black
                Else
                    itemX.SubItems.Item(1).ForeColor = Color.Red
                End If

                lvResults1.Items.Add(itemX)
            Next
[code]

Thanks again
Sb
 
I'll assume, because you have subitems, that your view is either Tile, or Details.

You are changing the color of one of the subitems.

In Tile mode it appears that this would work - the Item, and subitems have different colors. However it Details mode, it appears the color is determined by the item - not the subitems. Try setting the color to itemX.ForeColor instead.
 
Thank you that is the problem.

I was trying to follow what I had done in VB6 to get the same result.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top