Thanks Arun, especially, and others for replying. I tried your
method, Arun, and it will change the font and style of the selected
item as you suggest, but I guess I still wasn't clear, because I
wanted the dropdown to contain mixed fonts. This is my solution after
a struggle using google. I guess my major problem was how to ask the
question!
First, I have to set the drawmode of the combobox in my form_load
event:
CurComboBox.DrawMode = DrawMode.OwnerDrawVariable
Then, every time CurComboBox is selected, the code in
CurComboBox_DrawItem, if it exists, is called. I do this:
Private Sub CurComboBox_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles CurComboBox.DrawItem
Dim myFont As System.Drawing.Font
If CONDITION = TRUE Then
myFont = New Font(FontFamily.Families(25), 11,
FontStyle.Italic)
Else
myFont = New Font(FontFamily.Families(25), 11,
FontStyle.Regular)
End If
e.Graphics.DrawString(L3Names(e.Index + 1), myFont,
Brushes.Black, e.Bounds.Height, e.Bounds.Top)
End Sub
Note a couple of things:
1) This routine is called for every item you have loaded in the
combobox. I only have 15 items loaded, so it's pretty quick. If you
have a lot, I guess it might be a handicap, but you might not use a
combox in that situation.
2) CONDITION is anything I want to test. if the item in the list
contains "a", for example. In my case, I want to display the 15 items
differently, depending on the condition of something else in the
form. If I'm looking at young animals, I want to highlight items 1,3,
6 and 7 for example. If I'm looking at older animals, I will want to
highlight 2, 4, 5 and all the other items.
On Dec 20, 9:41 am, "ARUN KUMAR" <
carunkumar1...@gmail.com> wrote:
> Hai Arpaket,
>
> Now I am clear ie what u need
>
> First set the properties for the combo box
>
> DropDownStyle = DropDownList
>
> Add the item dynamically as previous but don't change font in that loop
> instead of that you can write the procedure in n
> SelectionChangeCommitted event
> (See in event properties)
>
> Private Sub CurComboBox_SelectionChangeCommitted(ByVal sender AsSystem.Object,
> ByVal e As System.EventArgs) Handles CurComboBox.SelectionChangeCommitted
>
> If CurComboBox.Text.Contains("a") Then
>
> CurComboBox.Font = New Font("Arial", 8, FontStyle.Italic)
>
> CurComboBox.BackColor = Color.Wheat
>
> Else
>
> CurComboBox.Font = New Font("Arial", 8, FontStyle.Regular)
>
> CurComboBox.BackColor = Color.White
>
> End If
>
> End Sub
>
> This event occurs when user select the item from combo box
>
> When the even t fire check the current text contains "a" if it true then
> change the font style and color so this will highlighted as your desire
>
> I think this is satisfy you
>
> I am wait for your reply
>
> 2008/12/20 Arpaket <
rick.paque...@gmail.com>