开发者

VB.NET ComboBox - Need to force a redraw when a key is pressed when it is dropped down

I am using a DrawItem and MeasureItem events to paint a combobox with a DrawMode of OwnerDrawVariable.

Basically, I'm trying to 开发者_开发知识库have the user highlight a selection with the mouse, and then press the space bar to toggle the Save status of a song list. Then I call the Me.Refresh() event for the form in an attempt to redraw the form and the ComboBox.

The problem that I am running into is that only the Combobox itself (not the drop-down area) that is a control on the main form is redrawing, and the text that is behind the mouse-highlighted selection of the drop-down list is not changing from Red to Black as I believe it should. If I move the mouse to another selection, then the color does in fact update.

Here is a snippet of the code.

    If (e.KeyCode = Keys.Space) Then
        If cmbList.SelectedItem IsNot Nothing Then
            With DirectCast(cmbList.SelectedItem, SongTitle)
                .bSave = Not .bSave
            End With
        End If
    End If

    e.Handled = True

    Me.Refresh()

Thanks for any help you can provide.


You need to use .RefreshItem/.RefreshItems instead of .Refresh.

See this question: Dynamically changing the text of items in a Winforms ComboBox

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜