Mostafa
Mostafa

Reputation: 111

disable or cancel combobox SelectedIndexChanged event with code?

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 ?

Upvotes: 0

Views: 5131

Answers (4)

andy
andy

Reputation: 6079

  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

Upvotes: 1

Ramashankar
Ramashankar

Reputation: 1658

ComboBox comboBox = new  ComboBox();

Subscribe to SelectedIndexChanged event

comboBox.SelectedIndexChanged += comboBox_SelectedIndexChanged;

Use below code to unsubscribe the SelectedIndexChanged event

comboBox.SelectedIndexChanged -= comboBox_SelectedIndexChanged;

Upvotes: 4

Sriram Sakthivel
Sriram Sakthivel

Reputation: 73502

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.

Upvotes: 1

Prasanna
Prasanna

Reputation: 760

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

combo1.SelectedIndexChanged -= combo1_SelectedIndexChanged;

Upvotes: 0

Related Questions