Quote Originally Posted by dunfiddlin View Post
It's all in those e.State values!

vb.net Code:
  1. Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
  2.         e.DrawBackground()
  3.         'GET ITEM TO DRAW
  4.         If Not e.Index = -1 Then
  5.             Dim myItem As ColoredComboboxItem = DirectCast(ComboBox1.Items(e.Index), ColoredComboboxItem)
  6.             'DRAW TEXT USING SPECIFIED FONT AND COLOR
  7.             ListBox1.Items.Add(CInt(e.State).ToString)
  8.             If e.State = 769 Or e.State = 785 Or e.State = 4881 Then
  9.                 e.Graphics.DrawString(myItem.Text, e.Font, New SolidBrush(Color.White), e.Bounds)
  10.             Else
  11.                 e.Graphics.DrawString(myItem.Text, e.Font, New SolidBrush(myItem.Color), e.Bounds)
  12.             End If
  13.         End If
  14.         e.DrawFocusRectangle()
  15.     End Sub
You should absolutely never be comparing a variable or property whose type is an Enum with numbers like that. Absolutely NEVER. As Edgemeal has shown, if you're interested in one specific value then you can pick that value out of an arbitrary combination regardless of what the other values are with a bitwise logic. If you're interested in specific combinations then you should specify those combinations as their Enum values, not as numbers. To combine two Enum values you use the bitwise Or operator. Or is to combine, And is to test, Xor is to toggle, And Not is to remove.