You, sir, are in luck!
It just so happened that I visited a coworker's office just as he was looking at a page that I had seen earlier this morning while trying to research a way to help you. We got to talking and it turns out what you want to do is quite possible!
On a ComboBox, there is a property called DrawMode. You can change this so that you can handle the way a combo box item is drawn. There are two modes in addition to
Normal, one is
OwnerDrawFixed and the other is
OwnerDrawVariable. These have to do with the width of the combo box pane... you can look these up on MSDN for more information.
Suffice it to say, if the DrawMode is set to one of these, drawing is now handled by the DrawItem event, which you can attach an event handler to and draw whichever way you like. Here's a rough breakdown of what you'd want to do... I'll leave it to you to learn the details though :)
- private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
-
{
-
Graphics g = e.Graphics;
-
ComboBox theCB = sender as ComboBox;
-
-
if (theCB != null && e.Index >= 0 && e.Index < theCB.Items.Count)
-
{
-
// Get the text
-
// Get the background colour for this istem
-
-
if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit)
-
{
-
// Draw an item that is showing in the combobox when not dropped down
-
}
-
else if ((e.State & DrawItemState.Selected) == DrawItemState.Selected )
-
{
-
// Draw an item that is selected
-
}
-
else
-
{
-
// Draw a normal item
-
}
-
}
-
}
(Note, all credit for this slick little solution doesn't belong to me :D I was just a crazy fluke that my coworker just happened to be working on a similar problem. It was a great chance for me to learn something new about .NET though!)