Hi,
is it possible to format a combobox item in C#?
Make an item bold, change color....
Hi,
is it possible to format a combobox item in C#?
Make an item bold, change color....
Yes, but with creating your own ComboBox with custom drawing See here on MSDN
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);
}
No, there's no built-in property to do it. You'll have to built your own control and override the rendering.
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