Hi,

I am new toVB.NET. However, I have years of programming experience and
a lot of VBA implementation.

In my application I change the forecolor of ComboBox items based on an
algorithm.
The code to change the forecolor is as follows:

Public Class KeywordItem
Public ItemText As String
Public NewItem As Boolean
End Class
.....
.DrawMode = DrawMode.OwnerDrawFixed
.....
Private Sub cboSearchKeywords_DrawItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles
cboSearchKeywords.DrawItem
Dim x As Single = e.Bounds.X
Dim y As Single = e.Bounds.Y
Dim CboText As String = Nothing

If (e.Index < 0) Then Return

e.DrawBackground()
If NewItem(e.Index, CboText) Then
Using NewItemBrush As New SolidBrush(Color.FromName("ActiveCaption"))
e.Graphics.DrawString(CboText, Me.Font, NewItemBrush, x, y)
End Using
Else
Using NewItemBrush As New SolidBrush(Color.Black)
e.Graphics.DrawString(CboText, Me.Font, NewItemBrush, x, y)
End Using
End If
End Sub

Private Function NewItem(ByVal ItemIndex As Integer, ByRef ItemText As
String) As Boolean
Dim KeywordItem As KeywordItem

KeywordItem = CboArray(ItemIndex)
ItemText = KeywordItem.ItemText
Return KeywordItem.NewItem
End Function

The item forecolor is changed alright. However, the item displayed in
the text box portion of the ComboBox shows correctly but without any
modifications. How do I 'force' the text displayed to be the same color
as the selected item? I have searched the internet and these groups but
cannot find an answer. I am sure this question has been asked and
answered.

Thanks in advance for any help. If this query is in the wrong group
please advise.

Jerry B



Reply via email to