c# - Accessing a Parent form button from a Child form button -


i have program has parent form creates child form. upon clicking updatebutton within child form, want searchbutton within parent form fire.

however error protection reasons. have tried setting public see, still wont work me.

error 1 'salessystem.systemform.searchbutton' inaccessible due protection level salessystem\updateform.cs 111 20 salessystem

this have far.

parent code

namespace salessystem {     public partial class systemform : form     {         public systemform()         {             initializecomponent();         }              protected void searchbutton_click(object sender, eventargs e)         {            //search code         }          private void updatebutton_click(object sender, eventargs e)         {             try             {                 updateform upform = new updateform(resultbox.selecteditems[0].text,            dbdirec, dbfname);                 upform.showdialog(this);             }             catch (exception)             {                 //             }         }     } 

child code

namespace salessystem {     public partial class updateform : form     {         public updateform(string selectedperson, string dbdirec, string dbfname)         {             initializecomponent();          }          private void updatebutton_click(object sender, eventargs e)         {             //do stuff              systemform parent = (systemform)this.owner;             parent.searchbutton.performclick();              this.close();         }     } } 

your searchbutton button control set private default in winform. you've said set public assume mean you've set in code you've posted public. there few ways fix this. direct fix go visual studio designer, select button, , set modifier property internal or public.

however, seems you're closing form straight after i'd have parent form subscribe formclosing event of form.

updateform upform = new updateform(resultbox.selecteditems[0].text, dbdirec, dbfname); upform.formclosing += (s, o) =>       {           //your code parent class should       }; upform.showdialog(this); 

if you're not closing form can create own event handler parent form subscribes to.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -