naura pax

naura pax

  • NA
  • 1.2k
  • 88.1k

Event unsubscription in another file

Oct 23 2009 3:43 AM

hi,
I am working in a window project, which has a reference of a utility project that contains generic methods. for example one for binding combobox with dataset at runtime-:
 

ComboUtils
.FillComboBox(cmbSubRegister, RGMaster.GetRegisterByParentID(Convert.ToInt32(cmbRegister.SelectedValue), false), true, "RegisterName", "RegisterID");

The ComboUtils.Fillcombobox function has follwoing definition
 

public static void FillComboBox(ComboBox cmb, object obj, bool valFieldRequired, string dispField, string valField) {
if (obj.GetType().ToString() == "System.Data.DataSet")
{
cmb.DisplayMember = dispField;
if (valFieldRequired)
cmb.ValueMember = valField;
cmb.DataSource = ((
DataSet)obj).Tables[0];
}
Now the problem is that selectedindex changed event gets fired.
I tried to unsubscribe selectedindexchanged event from combobox object being passed and later resusbscribe after datasource has been set but i just can't get reference of the event handler in this file.
-: EventHandler ev=cmb.SelectedIndexChanged gives error that it can only be at the left hand side of += operator.
Can somebody tell me how to do that?
Please.. thanks in advance.

Answers (13)