Listview item background colour not being displayed

Hi,  I've got a listview and I need to change the backcolor of the first listviewitem. Although this is easily done, however this is not always shown on screen; however if you press on the listview the color comes in.  It sorts of needs of a refresh or some type of on-focus event
any ideas how can I avoid clicking on the listview to refresh this control please?
Who is Participating?
borgb002Connect With a Mentor Author Commented:
Found a solution to those who might be interested. I have made a work around by selecting the list view item. see attached snippet

I hope this helps the others having a similar problem. Now it is working fine!

For lvMyItem as listviewitem in lvItems
    if lvMyItem.SubItems(0).Text = "Change this colour" then
        lvMyItem.backcolor =
        lvMyItem.Selected = TRUE      'this simple line solved my problem!!!
    end if
next for

Open in new window

Well to instigate a control refresh at any point, you can simply call .Refresh().

How are you changing the back color though? Because there might be a more elegant way of achieving it.
Basically, changing the color as follows should be enough:

myList.SelectedItems[0].BackColor = Color.Blue;

myList.SelectedItems(0).BackColor = Color.Blue
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

borgb002Author Commented:
tried the refresh :(


for each lv as listviewitem in MyListview
   if lv.subitems(0).text="test" then

borgb002Author Commented:

mine is not a problem of not know how to change the back color. It is more of a problem that sometimes when the form comes up the backcolor is shown and in other times it doesnt. when it doesn't, if I left click on the listview (sort of to repaint or to trigger the on focus event) the color comes! funny??

Yea i knew that, but sometimes you can change the colour of a referenced listviewitem rather than the actual object itself, causing nothing to happen.

You could try:
   lstSoftwareData.RedrawItems(0, lstSoftwareData.Items.Count - 1, False)

And/or :

I think have some kind of issue with your operating system, rather than your code syntax.
I am having in the same problem, running a Visual Studio 2008 program that colors Listviewitems.
On some workstations coloring Listviewitems works fine, on others it does not work.
Compared .NET Frameworks - > identical!
Checked Video and Videosettings on Operating Systems -> no success!
Help needed!

You could try installing the latest service packs for visual studio and then re-compiling your exe's. That would be my next step...

Visual Studio 2005:

Visual Studio 2008:

I updated mine today and was suprised at the sheer size of the update. ALOT of bugs were fixed in this service pack, so its definately worth a shot in your cases.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.