Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i put a background color or just simply change the color of a text in a listbox so that when an error occur during a query, the item would simply be color red?
Posted

It's not as simple as just setting a property! Basically, you have to draw it yourself... There is an example here: Stack overflow[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Jul-11 11:36am    
Sure, a 5. Alternative could be a free content model offered by WPF -- please see my solution.
--SA
Here is a control of mine that does this[^]. (It also does some other things – if literally all you want is different coloured text, the owner draw solution that Griff linked to will probably do the job.) It's not as trivial as it should be.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Jul-11 11:36am    
Very good, my 5.
Alternative could be a free content model offered by WPF -- please see my solution.
--SA
Espen Harlinn 12-Jul-11 12:28pm    
Nice article, my 5
I'd like to rate it but:"There was an error while trying to rate this item. Please try again later"
This is quite possible; and Bob and Griff provided nice solutions.
I would also add that these requirements are not very natural for System.Windows.Forms, but something that is already available in WPF, where list or tree items can contain any content. Consider switching to WPF to use the benefits of free content model.

See http://msdn.microsoft.com/en-us/library/bb613548%28v=VS.100%29.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900