c# - Perform a dynamic button click when the button ids found on the form -


i create button dynamically on form each product this:

button btnstore = new button(); btnstore.text = "store"; btnstore.height = 30; btnstore.width = 80; btnstore.name = "btnstorecv" + name + row[7].tostring(); btnstore.location = new point(ptx + 750, pty); btnstore.click +=btnstore_click; btnstore.visible = false; pt.controls.add(btnstore); 

then on button click search form product buttons , if finds it, want perform click event of button.

this have far not working:

private void btnsavecounts_click(object sender, eventargs e) {     foreach (panel p in pnls)     {        ienumerable<button> buttons = p.controls.oftype<button>();        foreach (button button in buttons)        {             if(button.name.contains("cv"))             {                messagebox.show("yes");             }        }     } } 

i have tried aswell:

private void btnsavecounts_click(object sender, eventargs e) {     foreach (panel p in pnls)     {          ienumerable<button> buttons = p.controls.oftype<button>();          foreach (button button in buttons)          {              if(button.name.contains("cv"))              {                 button.click += button_click;                 button.performclick();                 //messagebox.show("yes");              }          }     } }  void button_click(object sender, eventargs e) {    storenumbers(0, sender); } 

is there way perform button's click event.


Comments