I'm trying to make certain items in a combobox a different color using the DrawItem event. I've done this many times before but in this instance I keep getting a value of -1 for the e.index variable.
Isn't DrawItem called when there actually is at least one item in the combobox? A value of -1 for e.index means it's empty (which it shouldn't be in my case because I added the items in the forms Load event). I set ItemDraw mode to OwnerFixed. Am I missing some other setting?
Code:Private Sub cbCollege_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cbCollege.DrawItem e.DrawBackground() Dim myForeColor As Color = Color.Black Dim myBrush As Brush = New SolidBrush(Color.White) If 'Test for color change myForeColor = Color.Blue End if e.Graphics.FillRectangle(myBrush, e.Bounds) myBrush = New SolidBrush(myForeColor) e.Graphics.DrawString(sender.Items(e.Index).ToString(), New Font("Calibri", 12, FontStyle.Bold), myBrush, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)) e.DrawFocusRectangle() End Sub





Reply With Quote