How can I set the background color of a specific item in a System.Windows.Forms.ListBox? I would like to be able to set multiple ones if possible.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Complete sample
Probably the only way to accomplish that is to draw the items yourself.
Set the
DrawMode
toOwnerDrawFixed
and code something like this on the DrawItem event:
Second option would be using a ListView, although they have an other way of implementations (not really data bound, but more flexible in way of columns)
Thanks for the answer by Grad van Horck, it guided me in the correct direction.
To support text (not just background color) here is my fully working code:
The above adds to the given code and will show the proper text plus highlight selected item.
If what you mean by setting multiple background colors is setting a different background color for each item, this isn't possible with a ListBox, but IS with a ListView, with something like: