Home All Groups Group Topic Archive Search About

ComboBox SelectionChangeCommitted event fires twice

Author
19 Jul 2006 4:00 PM
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 ##################

Author
19 Jul 2006 9:40 PM
tommaso.gastaldi
Hi ML,
I have tested it with VS2005. This code does not show the problem you
report (?).

-tom

d***@globetrotter.net ha scritto:

Show quoteHide quote
> 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 ##################
Author
20 Jul 2006 2:05 AM
Mic
Hi Tom,

Sorry I did not specify that I'm using VS .Net 2003.


tommaso.gasta***@uniroma1.it wrote:
Show quoteHide quote
> Hi ML,
> I have tested it with VS2005. This code does not show the problem you
> report (?).
>
> -tom
>
> d***@globetrotter.net ha scritto:
>
> > 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 ##################
Author
20 Jul 2006 2:37 AM
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

<d***@globetrotter.net> schreef in bericht
Show quoteHide quote
news:1153324853.715505.123240@m79g2000cwm.googlegroups.com...
> 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 ##################
>
Author
20 Jul 2006 10:31 AM
Larry Lard
d***@globetrotter.net wrote:
> 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.

--
Larry Lard
larryl***@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Author
20 Jul 2006 11:31 AM
Cor Ligthert [MVP]
Docw,

I call the combobox for myself always the bugbox.

By the way, you know that there is a servicepack for Net 1.1, I don't know
if your problem is fixed in that.

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=262d25e3-f589-4842-8157-034d1e7cf3a3

Cor




<d***@globetrotter.net> schreef in bericht
Show quoteHide quote
news:1153324853.715505.123240@m79g2000cwm.googlegroups.com...
> 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 ##################
>