ComboBox SelectionChangeCommitted event fires twice

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • docw@globetrotter.net

    #1

    ComboBox SelectionChangeCommitted event fires twice

    SelectionChange Committed 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
    SelectionChange Committed event is fired twice.

    How can I cancel the second event firing ?

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

    Private Sub FormTest_Load(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    ComboBox1.DropD ownStyle = ComboBoxStyle.D ropDownList

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

    Private Sub ComboBox1_Selec tionChangeCommi tted(ByVal sender As
    Object, ByVal e As System.EventArg s) Handles
    ComboBox1.Selec tionChangeCommi tted

    MsgBox("test")

    End Sub

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

  • tommaso.gastaldi@uniroma1.it

    #2
    Re: ComboBox SelectionChange Committed event fires twice

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

    -tom

    docw@globetrott er.net ha scritto:
    SelectionChange Committed 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
    SelectionChange Committed event is fired twice.
    >
    How can I cancel the second event firing ?
    >
    Thanks
    ML
    '#### BEGIN CODE ############### ###
    >
    Private Sub FormTest_Load(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    ComboBox1.DropD ownStyle = ComboBoxStyle.D ropDownList
    >
    ComboBox1.Items .Add("My item 1")
    ComboBox1.Items .Add("My item 2")
    ComboBox1.Items .Add("My item 3")
    End Sub
    >
    Private Sub ComboBox1_Selec tionChangeCommi tted(ByVal sender As
    Object, ByVal e As System.EventArg s) Handles
    ComboBox1.Selec tionChangeCommi tted
    >
    MsgBox("test")
    >
    End Sub
    >
    '#### END CODE ############### ###

    Comment

    • Mic

      #3
      Re: ComboBox SelectionChange Committed event fires twice

      Hi Tom,

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


      tommaso.gastald i@uniroma1.it wrote:
      Hi ML,
      I have tested it with VS2005. This code does not show the problem you
      report (?).
      >
      -tom
      >
      docw@globetrott er.net ha scritto:
      >
      SelectionChange Committed 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
      SelectionChange Committed event is fired twice.

      How can I cancel the second event firing ?

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

      Private Sub FormTest_Load(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles MyBase.Load
      ComboBox1.DropD ownStyle = ComboBoxStyle.D ropDownList

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

      Private Sub ComboBox1_Selec tionChangeCommi tted(ByVal sender As
      Object, ByVal e As System.EventArg s) Handles
      ComboBox1.Selec tionChangeCommi tted

      MsgBox("test")

      End Sub

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

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: ComboBox SelectionChange Committed event fires twice

        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

        <docw@globetrot ter.netschreef in bericht
        news:1153324853 .715505.123240@ m79g2000cwm.goo glegroups.com.. .
        SelectionChange Committed 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
        SelectionChange Committed event is fired twice.
        >
        How can I cancel the second event firing ?
        >
        Thanks
        ML
        '#### BEGIN CODE ############### ###
        >
        Private Sub FormTest_Load(B yVal sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load
        ComboBox1.DropD ownStyle = ComboBoxStyle.D ropDownList
        >
        ComboBox1.Items .Add("My item 1")
        ComboBox1.Items .Add("My item 2")
        ComboBox1.Items .Add("My item 3")
        End Sub
        >
        Private Sub ComboBox1_Selec tionChangeCommi tted(ByVal sender As
        Object, ByVal e As System.EventArg s) Handles
        ComboBox1.Selec tionChangeCommi tted
        >
        MsgBox("test")
        >
        End Sub
        >
        '#### END CODE ############### ###
        >

        Comment

        • Larry Lard

          #5
          Re: ComboBox SelectionChange Committed event fires twice

          docw@globetrott er.net wrote:
          SelectionChange Committed 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
          SelectionChange Committed 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
          SelectionChange Committed but the new selection is the same as the
          current stored selection, don't do anything.

          --
          Larry Lard
          larrylard@googl email.com
          The address is real, but unread - please reply to the group
          For VB and C# questions - tell us which version

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: ComboBox SelectionChange Committed event fires twice

            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/d...7-034d1e7cf3a3

            Cor




            <docw@globetrot ter.netschreef in bericht
            news:1153324853 .715505.123240@ m79g2000cwm.goo glegroups.com.. .
            SelectionChange Committed 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
            SelectionChange Committed event is fired twice.
            >
            How can I cancel the second event firing ?
            >
            Thanks
            ML
            '#### BEGIN CODE ############### ###
            >
            Private Sub FormTest_Load(B yVal sender As System.Object, ByVal e As
            System.EventArg s) Handles MyBase.Load
            ComboBox1.DropD ownStyle = ComboBoxStyle.D ropDownList
            >
            ComboBox1.Items .Add("My item 1")
            ComboBox1.Items .Add("My item 2")
            ComboBox1.Items .Add("My item 3")
            End Sub
            >
            Private Sub ComboBox1_Selec tionChangeCommi tted(ByVal sender As
            Object, ByVal e As System.EventArg s) Handles
            ComboBox1.Selec tionChangeCommi tted
            >
            MsgBox("test")
            >
            End Sub
            >
            '#### END CODE ############### ###
            >

            Comment

            Working...