Guys
I was hoping someone could please help me. I have a piece of code which works fine, but looks incredibly messy and ideally i'd like to make it easier to reuse.
NavBar1 is a usercontrol, which has a collection of NavBarPanels on it, these are custom controls inheriting from the Panel control. The NavBarPanels have a number of NavBarSubButton's on it, which are also custom controls inheriting from the button control.
I have tried both of the following, but they both come up with 'Object reference not set to an instace of a object'.
As their are several NavBarPanels, the method i have working looks a little untidy and unwieldy!
Also is there a simple way of using delegates via strings? For example:
I would just like to pass the delegate method name into it via code. The delegate name being stored into a database, ideally I would like to store the entire method in a database, but i'm guessing this would be much more complex!
Thanks for any help you may be able to give.
I was hoping someone could please help me. I have a piece of code which works fine, but looks incredibly messy and ideally i'd like to make it easier to reuse.
Code:
For Each np As Control In NavBar1.Controls
If TypeOf np Is NavBarPanel Then
If np.Name = "NavPanelCalendar" Then
Dim nsb As NavBarSubButton = np.Controls("subBtnUpcoming")
AddHandler nsb.Click, AddressOf frmUpcoming
End If
End If
Next
NavBar1 is a usercontrol, which has a collection of NavBarPanels on it, these are custom controls inheriting from the Panel control. The NavBarPanels have a number of NavBarSubButton's on it, which are also custom controls inheriting from the button control.
I have tried both of the following, but they both come up with 'Object reference not set to an instace of a object'.
Code:
'Attempt 1
Dim nsb2 As NavBarSubButton = NavBar1.Controls("NavPanelCalender").Controls("subBtnUpcoming")
AddHandler nsb2.Click, AddressOf frmUpcoming
'Attempt 2
AddHandler (NavBar1.Controls("NavPanelCalender").Controls("subBtnUpcoming")).Click, AddressOf frmUpcoming
As their are several NavBarPanels, the method i have working looks a little untidy and unwieldy!
Also is there a simple way of using delegates via strings? For example:
Code:
AddHandler nsb2.Click, AddressOf frmUpcoming
Thanks for any help you may be able to give.