Colour Individual Items in a winforms ComboBox?

You may try DrawItem event of ComboBox. Keep your dates on a list and compare them with ID’s and brush your items.

private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{    
    // Draw the background 
    e.DrawBackground();        

    // Get the item text    
    string text = ((ComboBox)sender).Items[e.Index].ToString();

    // Determine the forecolor based on whether or not the item is selected    
    Brush brush;
    if (YourListOfDates[e.Index] < DateTime.Now)// compare  date with your list.  
    {
        brush = Brushes.Red;
    }
    else
    {
        brush = Brushes.Green;
    }

    // Draw the text    
    e.Graphics.DrawString(text, ((Control)sender).Font, brush, e.Bounds.X, e.Bounds.Y);
}

To fire this event (thanks to @Bolu)

You need to change ComboBox.DrawMode
to OwnerDrawFixed/OwnerDrawVariable to
fire the comboBox_DrawItem

Leave a Comment