Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Listview item background colour not being displayed

Posted on 2009-04-01
Medium Priority
Last Modified: 2013-11-07
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?
Question by:borgb002
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Expert Comment

ID: 24047856
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.

Expert Comment

ID: 24047871
Basically, changing the color as follows should be enough:

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

myList.SelectedItems(0).BackColor = Color.Blue

Author Comment

ID: 24047872
tried the refresh :(


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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 24047889

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??


Expert Comment

ID: 24048028
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.

Expert Comment

ID: 24156551
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!


Expert Comment

ID: 24169482
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.

Accepted Solution

borgb002 earned 0 total points
ID: 24176217
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 = colors.red
        lvMyItem.Selected = TRUE      'this simple line solved my problem!!!
    end if
next for

Open in new window


Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question