Changing listview cells backcolor...

lidds

Junior Contributor
Joined
Nov 9, 2004
Messages
210
I have a listview that has 2 columns and 2 rows what I want to be able to do is change the backcolor but just for individual cells. I have used the following code but it does not seem to have any effect, can anyone see why?

Code:
me.lstview.items(0).subitems(0).backcolor = system.drawings.color.red

Cheers

Simon
 
You'll need to set the UseItemStyleForSubItems to False either during or after the listview is populated.

Visual Basic:
        'creates cell independance and allows cells to be individually colored
        For i = 0 To ListView1.Items.Count - 1
            ListView1.Items(i).UseItemStyleForSubItems = False
        Next

Then you can set any cell to any color.
 
DiverDan,

That worked a treat, thankyou.

Have one little problem now though. I am stroring the colour that I wish the cells to be within a MSDE table. I have no problem in getting the information from the table and I then populate the list accordinly. The problem I have is when I need to use the variable 'dispColour' that contains the colour of the cell which is obtained from the table i.e. dim dispColour as string = 'Red' and adding this to the system.drawing.color code.

e.g.
Code:
me.lstView.items(0).subitems(0).backcolor = system.drawings.color.dispColour

VB.net does not like the code above. Have you any suggestions.

Cheers

Simon
 
Back
Top