0

I need to working with combobox SelectedIndexChanged event, but in some cases I want when click button cancel SelectedIndexChanged event or code related to this event stop working ?

Max
  • 12,622
  • 16
  • 73
  • 101
Mostafa
  • 91
  • 2
  • 12

4 Answers4

4
ComboBox comboBox = new  ComboBox();

Subscribe to SelectedIndexChanged event

comboBox.SelectedIndexChanged += comboBox_SelectedIndexChanged;

Use below code to unsubscribe the SelectedIndexChanged event

comboBox.SelectedIndexChanged -= comboBox_SelectedIndexChanged;
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Ramashankar
  • 1,598
  • 10
  • 14
1

There are number of options

  1. You can unsubscribe the event temporarily
  2. You can maintain a flag to check whether you need to process it or not.
Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
1
  1. You can disable/enable the combobox, on the basis of button click
  2. You can unsubscribe the SelectedIndexChanged as told by @Ramashankar
  3. Maintain a flag to check whether event has to be executed or not
user247702
  • 23,641
  • 15
  • 110
  • 157
andy
  • 5,979
  • 2
  • 27
  • 49
0

You can unsubscribe the events like the below upon clicking on the button:

combo1.SelectedIndexChanged -= combo1_SelectedIndexChanged;
Prasanna
  • 760
  • 2
  • 6
  • 16