VB.NET - Multi-colored listbox

woklet

Member
Joined
Mar 4, 2005
Messages
15
Programming Experience
5-10
I'm programatically adding items to my listbox in vb.net and would like to change the color of a line to red if its an 'important' item. Does anyone have any code snippets on how to change the color of a particular line in a listbox; or upon adding it if there is a way to set the color?

Any help would be appreciated,
Thanks
Ben
 
Umm, I couldn't exactly figure out how to get this to work but with some research and experimenting I found that the DataMode property on your listbox will need to be set to either OwnerDrawFixed or OwnerDrawVariable.

<example>
listBox1.DrawMode = DrawMode.OwnerDrawFixed </example>

I think playing with DrawItemEventArgs
, you can draw items in different colors based on the index.

Hopefully, someone else can explain more about this because it's a bit beyond me. =o)

M.Cold
 
Back
Top