Hi,
Am hoping someone can help. I want to change the colour of the autocomplete section of a combo box depending on the value of the item. I found the following code to do this for the main drop down section like so.
; Code:
Private Sub cbdept_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cbdept.DrawItem Dim c As System.Drawing.Color Dim dcomb As ComboBox Try dcomb = CType(sender, ComboBox) 'Sometimes calls this procedure with an index of -1 If e.Index < 0 Then e.DrawBackground() e.DrawFocusRectangle() Else 'Determine colour to use Select Case CType(dcomb.Items.Item(e.Index), DataRowView).Item(0).ToString Case "sales" c = Color.FromName("Blue") Case "IT" c = Color.FromName("Green") Case "Accounts" c = Color.FromName("Orange") Case "Red" c = Color.FromName("Red") Case Else c = Color.FromName("Red") End Select 'Carry out necessary procedures e.DrawBackground() e.DrawFocusRectangle() 'Create rectangle, fill it with desired colour, and add text e.Graphics.DrawRectangle(New Pen(c), New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)) e.Graphics.FillRectangle(New SolidBrush(c), New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)) e.Graphics.DrawString(CType(dcomb.Items.Item(e.Index), DataRowView).Item(0).ToString, dcomb.Font, New SolidBrush(Color.Black), New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)) End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
Not sure how to do the same thing with the autocomplete section though.
Any help would be apreciated.
Cheers




Reply With Quote