tags:

views:

486

answers:

4

Hi,

is it possible to format a combobox item in C#?

Make an item bold, change color....

A: 

Yes, but with creating your own ComboBox with custom drawing See here on MSDN

PoweRoy
+2  A: 

You can do this by setting the DrawMode to OwnerDrawFixed which allows you to manually draw the items using the DrawItem event.

comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
comboBox1.DrawItem += new DrawItemEventHandler(comboBox1_DrawItem);

private void comboBox1_DrawItem(object sender, DrawItemEventArgs e) {    
    Font font = comboBox1.Font;
    Brush brush = Brushes.Black;
    string text = comboBox1.Items[e.Index]; 

    if (you want bold)
        font = new Font(font, FontStyle.Bold);

    if (you want green)
        brush = Brushes.Green;

    e.Graphics.DrawString(text, font, brush, e.Bounds);
}
Bob
A: 

No, there's no built-in property to do it. You'll have to built your own control and override the rendering.

Fabian Vilers
+1  A: 

Hello!

This link might help: http://www.johnkoerner.com/index.php?/archives/42-Conditionally-Formatting-ComboBox-Items-in-C.html

Talks about conditionally formatting items in a Combobox.

Hopefully that brings you closer to a solution to your problem.

Tony

Tony