jmc yes I only wanted the event fired once but because I added the handler to multiple buttons but only one button will be actually clicked, i need a way of clearing all the handlers to all the buttons.
shaggy I think your exactly right and it was 2) that was occuring.
E.g. Button 1-20 I add PopulateProducts handler. User selects Button1 which then clears the button text and now add's PopulateService handler.
The RemoveHandler code was working but I was only calling it the once thinking it would remove all instances of the handler.
All I have done now is in my clear method I call it for all the buttons on the grid evertime I move to re create the grid with new elements.
Code:For i = 0 To 35 GrdTableLayoutPanel.Controls(i).Text = "" GrdTableLayoutPanel.Controls(i).Enabled = False RemoveHandler GrdTableLayoutPanel.Controls(i).Click, AddressOf PopulateProducts RemoveHandler GrdTableLayoutPanel.Controls(i).Click, AddressOf PopulateServices Next
For those having same problem also look at the event handler itself. When I was calling the RemoveHandler PopulateProducts, I was getting the following warning:
Am still not very clear on this warning as am new to custom events but assigning the PopulateProducts event handler with 'sender' and 'e' did the trick. As suggested you can try to assign the event handler to a variable and use that but my current way works fine.The 'AddressOf' expression has no effect in this context because the method argument to 'AddressOf' requires a relaxed conversion to the delegate type of the event. Assign the 'AddressOf' expression to a variable, and use the variable to add or remove the method as the handler.
My new PopulateProducts is :
stannav I tried your module but i received object reference errors due to null controls. I'll take a look at it again and see if it can be usefull in other instances.Code:Private Sub PopulateProduct(ByVal sender As System.Object, ByVal e As System.EventArgs) 'some code in here End Sub
Thanks guys for leading me to my fix.






Reply With Quote
