Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. CombobBox SelectedIndexChanged Event

CombobBox SelectedIndexChanged Event

Scheduled Pinned Locked Moved C#
helpquestiondatabasedesign
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KrunalC
    wrote on last edited by
    #1

    I had posted this question two weeks back but till date no one has responed. Is this indeed an issue with the combobox? I hope I'm clear with my question and this time I will get some help from this forum. ComboBox control has got selectedindexchanged event. As the name suggest this event should fire when selected item change for the combobox. But this event fires even when the currently selected item is selected again from the dropdown list of combobox. e.g. if I have loaded following items in my combobox say item1 item2 item3 item4 with item1 as selected when my application starts. Now if from UI, I again select the "item1" (which is already selected in combo box) then also the selectedindexchanged event fires. In this case the index has not changed still the selectedindexchanged event fires. I find this bit strange. Is there anyway to findout when the selected item has changed by User. I want some kind of notification when user indeed changes the combobox selected item (not when combobox.selecteditem is set through code)? regards KC

    C M R 3 Replies Last reply
    0
    • K KrunalC

      I had posted this question two weeks back but till date no one has responed. Is this indeed an issue with the combobox? I hope I'm clear with my question and this time I will get some help from this forum. ComboBox control has got selectedindexchanged event. As the name suggest this event should fire when selected item change for the combobox. But this event fires even when the currently selected item is selected again from the dropdown list of combobox. e.g. if I have loaded following items in my combobox say item1 item2 item3 item4 with item1 as selected when my application starts. Now if from UI, I again select the "item1" (which is already selected in combo box) then also the selectedindexchanged event fires. In this case the index has not changed still the selectedindexchanged event fires. I find this bit strange. Is there anyway to findout when the selected item has changed by User. I want some kind of notification when user indeed changes the combobox selected item (not when combobox.selecteditem is set through code)? regards KC

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You have to store your selected index, and compare it to what is in the control after the event fires. The event should check first, then store the value for next time.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      K 1 Reply Last reply
      0
      • C Christian Graus

        You have to store your selected index, and compare it to what is in the control after the event fires. The event should check first, then store the value for next time.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        K Offline
        K Offline
        KrunalC
        wrote on last edited by
        #3

        Christian Thanks for your reply. I agree to your solution where I have to remember the previously selected index and match it with the newly selected index in the eventhandler. If new and previous indexes are same then skip the execution of handler. But this is not going to serve my purpose. What I want is, I want to skip the execution of ComboboxSelectedIndexChanged Eventhandler when the already selected item in the combobox is again selected by user (i.e. user clicks the combobox and select the same item again). I don't mind if combobox SelectedIndex changed event fires through some code i.e. ComboBox.SelectedIndex = 2; So in nutshell want to restrict the eventhandler when same item is selected through user interaction.

        C 1 Reply Last reply
        0
        • K KrunalC

          Christian Thanks for your reply. I agree to your solution where I have to remember the previously selected index and match it with the newly selected index in the eventhandler. If new and previous indexes are same then skip the execution of handler. But this is not going to serve my purpose. What I want is, I want to skip the execution of ComboboxSelectedIndexChanged Eventhandler when the already selected item in the combobox is again selected by user (i.e. user clicks the combobox and select the same item again). I don't mind if combobox SelectedIndex changed event fires through some code i.e. ComboBox.SelectedIndex = 2; So in nutshell want to restrict the eventhandler when same item is selected through user interaction.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Well, you plainly can't stop the event from firing. Until it fires, you can't make your code run at all.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          1 Reply Last reply
          0
          • K KrunalC

            I had posted this question two weeks back but till date no one has responed. Is this indeed an issue with the combobox? I hope I'm clear with my question and this time I will get some help from this forum. ComboBox control has got selectedindexchanged event. As the name suggest this event should fire when selected item change for the combobox. But this event fires even when the currently selected item is selected again from the dropdown list of combobox. e.g. if I have loaded following items in my combobox say item1 item2 item3 item4 with item1 as selected when my application starts. Now if from UI, I again select the "item1" (which is already selected in combo box) then also the selectedindexchanged event fires. In this case the index has not changed still the selectedindexchanged event fires. I find this bit strange. Is there anyway to findout when the selected item has changed by User. I want some kind of notification when user indeed changes the combobox selected item (not when combobox.selecteditem is set through code)? regards KC

            M Offline
            M Offline
            miestas
            wrote on last edited by
            #5

            You could combine it with TextChanged event ;)

            1 Reply Last reply
            0
            • K KrunalC

              I had posted this question two weeks back but till date no one has responed. Is this indeed an issue with the combobox? I hope I'm clear with my question and this time I will get some help from this forum. ComboBox control has got selectedindexchanged event. As the name suggest this event should fire when selected item change for the combobox. But this event fires even when the currently selected item is selected again from the dropdown list of combobox. e.g. if I have loaded following items in my combobox say item1 item2 item3 item4 with item1 as selected when my application starts. Now if from UI, I again select the "item1" (which is already selected in combo box) then also the selectedindexchanged event fires. In this case the index has not changed still the selectedindexchanged event fires. I find this bit strange. Is there anyway to findout when the selected item has changed by User. I want some kind of notification when user indeed changes the combobox selected item (not when combobox.selecteditem is set through code)? regards KC

              R Offline
              R Offline
              Rhys Gravell
              wrote on last edited by
              #6

              Try overriding the combobox control. Very, very basic example below;

              class ComboBoxWidget: System.Windows.Forms.ComboBox
              {
              	#region private member variables
              
              	private int \_selectedIndex = -1;
              
              	#endregion
              
              	#region overrides
              
              	protected override void OnSelectedIndexChanged( EventArgs e )
              	{
              		if( this.SelectedIndex != this.\_selectedIndex )
              		{
              			this.\_selectedIndex = this.SelectedIndex;
              			base.OnSelectedIndexChanged( e );
              		}
              	}
              
              	public override int SelectedIndex
              	{
              		get
              		{
              			return base.SelectedIndex;
              		}
              		set
              		{
              			this.\_selectedIndex = value;
              			base.SelectedIndex = this.\_selectedIndex;
              		}
              	}
              
              	#endregion
              }
              
              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups