C# ListViewItems sometimes lose their BackColor settings when I run the .exe file directly

P

polocar

Hello,
I'm developing a C# program using Visual Studio 2005 Professional
Edition.
In the main form I have inserted a ListView control that is populated
in a different way depending on the item selected in a ComboBox.
I have written a procedure that reads the ComboBox selected item and
populates the ListView according to that. The procedure uses a
"for" cycle: in every iteration it creates a ListViewItem, set its
SubItems and BackColor properties and add it to the ListView (the
BackColor is set to a color that depends on various factors).
When I run the program from Visual Studio everything goes ok, but when
I run the program from the .exe file created after the code generation,
in some cases the ListViewItems appear without their BackColor. If I
select the ListViewItems one by one, they finally take the BackColor
they should have been from the beginning.
The strange things are two:

1) The ListViewItems are without their BackColor only in some cases,
not all of them (if I select an item of the ComboBox, the ListView is
populated correctly; if I select the next item, the ListView is
populated without any BackColors), but it can't depend on the code!!!
(the way it handles the two cases is the same).

2) If the project runs under Visual Studio 2005, there is no bug, the
ListView is always populated with its ListViewItems having their
correct BackColors...

Do you know the reason of that?
Can someone help me to avoid this unpleasant behaviour when I run the
..exe file too?

Thank you very much
 
P

Peter Thornqvist

Are you using BeginUpdate/EndUpdate? Do you have a simple sample that shows
this behavior?
 
P

polocar

Hi Peter,
yes, I use the BeginUpdate/EndUpdate methods when I start/end to
populate the ListView.
The code I'm using at the moment is very long, but now I'll try to
semplify it and hope that in the semplified version the wrong behaviour
of the ListViewItems BackColor property remains the same...
 

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