views:

217

answers:

3

I'm working on a form that will display links to open different types of reports. This system has different types of users, so the users should only be able to see the links to the types of reports they can access.

Currently, the way I have this set up is that I have an ArrayList of LinkLabels, but the problem I'm having is how to have a LinkClicked event for each LinkLabel in the ArrayList so that it will bring up a form specific to each report.

+2  A: 

Actually, I would have a single event handler for all the linklabels, (add the handler during the databinding process of the ArrayList) with the name of the report to be loaded in the CommandName label of the LinkLabel. When the event handler fires, you would check the CommandName attribute and the fire off the appropriate functionality to load the given report.

Stephen Wrighton
A: 

Definitely recommend a single event handler for all of the dynamic LinkLabel instances.

I usually use a Hashtable where the key is the LinkLabel instance and the value is something that will be used within the click event (such as the report instance, if appropriate).

Then in the click event you use (for example)

Report r = m_TheTable[sender] as Report;
if( r != null ) r.DoSomething();
Craig Eddy
+2  A: 

You can apply the same event handler to every LinkLabel in your list and get the specific LinkLabel from the sender argument.

Austin Salonen