ComboBox SelectionChangeCommitted event fires twice

D

docw

SelectionChangeCommitted event fires twice

Hi,

Please have a look at the following ComboBox behavior.
With the code below, if you click in the dropdown list with the mouse
to select an item , everything is fine.

But if you use the Enter key to select in the dropdown list, the
SelectionChangeCommitted event is fired twice.

How can I cancel the second event firing ?

Thanks
ML
'#### BEGIN CODE ##################

Private Sub FormTest_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList

ComboBox1.Items.Add("My item 1")
ComboBox1.Items.Add("My item 2")
ComboBox1.Items.Add("My item 3")
End Sub

Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectionChangeCommitted

MsgBox("test")

End Sub

'#### END CODE ##################
 
T

tommaso.gastaldi

Hi ML,
I have tested it with VS2005. This code does not show the problem you
report (?).

-tom

(e-mail address removed) ha scritto:
 
C

Cor Ligthert [MVP]

ML,

In addition to Tommasso, I did not test it, but found it curious that you
would get an error with this code.

Are you sure that the error is not because that you are selecting inside the
event?

Cor
 
L

Larry Lard

SelectionChangeCommitted event fires twice

Hi,

Please have a look at the following ComboBox behavior.
With the code below, if you click in the dropdown list with the mouse
to select an item , everything is fine.

But if you use the Enter key to select in the dropdown list, the
SelectionChangeCommitted event is fired twice.

How can I cancel the second event firing ?

Reproduced in 2003 - thanks for the complete sample.

I think your options are:

- upgrade (I know this probably isn't an available option)
- rework your app so that it isn't a problem that this event fires twice
in these circumstances - how about you only do whatever you want to do
on selection change if the selection *actually changes* - ie, keep a
separate track of what the current selection is, and if you get a
SelectionChangeCommitted but the new selection is the same as the
current stored selection, don't do anything.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top