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-:
|
The ComboUtils.Fillcombobox function has follwoing definition
|
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.

Nilanka DharmadasaPosted Oct 26, 2009, 11:32 PM
You can do it using method overloading, without changing the method signature.
Deepak BhatiaPosted Oct 24, 2009, 4:19 AM
jingePosted Oct 23, 2009, 10:56 PM
naura paxPosted Oct 23, 2009, 9:23 AM
sorry i lost net connection.
Talking about your suggestion, I hope you tested that well, i had that thing in mind but the main problem is there are two many comboboxes accross two many forms many of which are not under my control that are using method.
if i change signature of the function the client code will break and everychange will have to be made that's why i was looking for a workaround.
Thanks anyways.
bebo
Nilanka DharmadasaPosted Oct 23, 2009, 7:27 AM
Why are you silent? What happened?
jingePosted Oct 23, 2009, 6:00 AM
I am confused, what did you want exactly? why does the above piece code not work for you. Hope you can elaborate it more.
Nilanka DharmadasaPosted Oct 23, 2009, 6:00 AM
Sorry. Now only I got ur problem. I think this solution should work.
When you pass values for the method you should pass like ths.
If this helps you, please accept my answer.
naura paxPosted Oct 23, 2009, 5:55 AM
pass your combobox , dataset, displaymember, valuemember
and try & do this in that function
jingePosted Oct 23, 2009, 5:38 AM
Does it work?
naura paxPosted Oct 23, 2009, 5:32 AM
there is no error i have reference for window project and all that.
point is at the time of setting datasource of combobox selectedindexchanged event gets fired, but that function is being run in another file where i can't get reference of event handler.
I want to remove event handler and reassign it to avoid selectedindexchanged from getting fired.
hope you got it.
jingePosted Oct 23, 2009, 5:24 AM
Let me explain why the error happens. First we all know that ComboBox has SelectedIndexChanged event, but why Visual Studio complies with error?
I think that's because in your utility project, you does not add reference to Windows.Forms.Controls assembly which is not added automatically when it is a libray project.
naura paxPosted Oct 23, 2009, 5:03 AM
selectedindexchanged event still gets fired.
can you explain what you are trying to do here? I didn't get it.. please.
Nilanka DharmadasaPosted Oct 23, 2009, 4:48 AM
If my answer helps you, pls accept it.