Results 1 to 8 of 8

Thread: [RESOLVED] Combobox Draw Item Issue

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    [RESOLVED] Combobox Draw Item Issue

    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
    Last edited by neef; Aug 15th, 2018 at 09:55 PM.
    Intermediate Level Programmer Extraordinaire

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width