Click here to Skip to main content
15,877,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys please help me in this.

I have a usercontrol I am using that in my home.xaml which is placed in listbox item template. It dynamically creates number of time as in my table.

My question is:

I need to create dynamically button click event where I can display a messagebox which contain data related to that particular button click

I came up a solution like:
C#
public  usercontrol()
{
    InitializeComponent();
    testButton.Click +=(s,e) =>
        {
             if(buttonclick != null )
                 buttonclick(s,e);
        };
...

Can you please explain to me how and where in the event click we can write messagebox?

Thank you!
Posted
Updated 3-Dec-10 2:44am
v2

Why don't you just use a more maintainable mechanism. Lamda expressions are obfuscatory and aren't always a good idea.

C#
...
testButton.Click += new EventArgs(button_Click);
...
<br />
private void buttonClick(object sender, EventArgs e)
{
  // do whatever you need to have done
}
 
Share this answer
 
Why don't you just use a more maintainable mechanism. Lamda expressions are obfuscatory and aren't always a good idea.

C#
...
testButton.Click += new EventArgs(button_Click);
...
<br />
private void buttonClick(object sender, EventArgs e)
{
  // do whatever you need to have done
}
 
Share this answer
 
Comments
Gautham Gorla 3-Dec-10 11:38am    
Thanks a lot John.. it worked for me....
hey guys I got the answer thanks for all the guys who ever was thinking of this question and here is the answer


public Usercontrol()
{
InitializeComponent();
ButtonExport.Click += new RoutedEventHandler(ButtonExport_Click);
}

void ButtonExport_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(TextHeader.Text);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900