Articles in this section
Category / Section

How to display the items of WinForms ComboBox (ComboBoxAdv) with different colors?

1 min read

Background settings

ComboBoxAdv uses a ListBox internally and you can use ListBox_DrawItem event to draw the ListBox entries with different backgrounds.

C#

void ListBox_DrawItem(object sender, DrawItemEventArgs e)
{
    e.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), e.Bounds);
    // set particular item Text color
    e.Graphics.DrawString(text, e.Font, new SolidBrush(Color.Purple), e.Bounds);     
}

 

VB

Private Sub ListBox_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs)
' set particular item backcolor
e.Graphics.FillRectangle(New SolidBrush(Color.LightBlue), e.Bounds)
' set particular item Text color
e.Graphics.DrawString(text, e.Font, New SolidBrush(Color.Purple), e.Bounds)
 

 

Sample: http://www.syncfusion.com/downloads/support/directtrac/204637/ze/ComboBox_items529015295

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied