D
David D Webb
I have a form with a number of buttons that are generated in a panel based
on the results of a query. They all use the same click event handler. I am
having trouble determining which button was pressed. I can only go by the
button text or the button position to distinguish them - neither of which
works well for my situation. Is there a better way? Should I create my own
button class inheiriting Button and add my own custom id fields?
Thanks/Dave
They are created as:
while (...)
{
Button btnClient = new Button();
btnClient.Location = new System.Drawing.Point(8, (numClients*32) + 8);
btnClient.Width = 150;
btnClient.Text = full_name;
btnClient.Click += new System.EventHandler(btnClient_Click);
pnlScroll.Controls.Add(btnClient);
numClients ++;
}
I have a generic handler for these buttons:
private void btnClient_Click(object sender, System.EventArgs e)
{
Button btnClient = (Button)sender;
// Determine which button was pressed here
}
on the results of a query. They all use the same click event handler. I am
having trouble determining which button was pressed. I can only go by the
button text or the button position to distinguish them - neither of which
works well for my situation. Is there a better way? Should I create my own
button class inheiriting Button and add my own custom id fields?
Thanks/Dave
They are created as:
while (...)
{
Button btnClient = new Button();
btnClient.Location = new System.Drawing.Point(8, (numClients*32) + 8);
btnClient.Width = 150;
btnClient.Text = full_name;
btnClient.Click += new System.EventHandler(btnClient_Click);
pnlScroll.Controls.Add(btnClient);
numClients ++;
}
I have a generic handler for these buttons:
private void btnClient_Click(object sender, System.EventArgs e)
{
Button btnClient = (Button)sender;
// Determine which button was pressed here
}