1

I am having a drop down and a radio button on my form. What i would like to do is i would like to call radio_CheckedChangedon drodown_SelectedIndexChanged. Can any one tell me the best way to do

Vivekh
  • 4,141
  • 11
  • 57
  • 102

4 Answers4

4

It's not possible to raise an event from outside the class the defines it, unless you inherit from it.

If your goal is to perform the same actions on both the RadioButton.CheckedChanged and DropDownList.SelectedIndexChanged events, you could extract the code in a separate method and invoke it from both event handlers:

public void radioButton_CheckedChanged(object sender, EventArgs e)
{
    DoSomething();
}

public void dropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
    DoSomething();
}

private void DoSomething()
{
    // ...
}
Community
  • 1
  • 1
Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
0

I may be over simplifying this but in your dropdown_SelectedIndexChanged you can just set the radio button value, which will fire the checked change event or if you don't want the value to change just call radio_CheckedChanged from within your dropdown_SelectedIndexChanged event.

DoctorMick
  • 6,703
  • 28
  • 26
0

Could you just update radio.Checked property so it will trigger an event automatically? The event holder is aware when to raise an event.

sll
  • 61,540
  • 22
  • 104
  • 156
-1

Just write radio_CheckedChanged(sender, EventArgs.Empty). Its very much like calling a method which is infact what it is.

EDIT

This is not an elegant way to do this so it would be better if you could encapsulate the code logic into seperate methods and then call these in the respective handlers based on your conditions

V4Vendetta
  • 37,194
  • 9
  • 78
  • 82