Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click Event for dynamically created buttons

Status
Not open for further replies.

jeffshex

Technical User
Jun 30, 2005
208
US
Hey all,
I need some help when it comes to handling a click event for a series of buttons that are created dynamically from XML.

I have a LoadXML method that creates rows for the buttons and names them with the "name" tag from the xml.
Is what I'm trying to do is have their click event open a folder or file (basically follow a hyperlink) to whatever is specified for the path in the "location" tag.

I thought that the best way would be to pass the location string to the event, but I an too new at this to know if that's even possible or if I need to look at another angle.

Can anyone lend some advice.
Thanks!
 
you need to wire the click event to the button
Code:
private Button button;

void the_initization_of_the_button()
{
   button = new Button();
   button.id = "the id";
   button.Text = "click me";
   button.Click += do_this_when_i_am_clicked;

   //add control to form
   this.Add(button);
}

public override void Dispose()
{
   button.Click -= do_this_when_i_am_clicked;
}

void do_this_when_i_am_clicked(object sender, EventArgs e)
{
   //dosomething
}
since you are creating a list of buttons from xml store a reference to the buttons in a List<Button> and add the buttons to the form and list. then cycle through the list in the dispose method to un-register each event when the form is disposed.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top