c# - Winform - SetFocus to textbox inside usercontrol on TabControl -


winform application multiple tabs on tabs replicated usercontrol

when clicking on particular tab, setfocus textbox within usercontrol. if possible within tabcontrol_selectedindexchanged event.

ex:

textbox name = txtone
txtone resides within usercontrola
usercontrola resides within tabcontrol.selectedtab.text = "tab2"

when click tab2 i'd focus set txtone.

i've tried: (and many other things!) usercontrola.controls["txtone"].selectall(); - returns object reference not set instance of object

thanks!

because txtone not immediate child of usercontrola, usercontrola.controls["txtone"] return null.

you can either dig way down control hierarchy control names (usercontrola.controls["famefd"].controls["txtone"]) or expose txtone public field or property in usercontrol class. latter this:

public textbox txtone {         {         return txtone;     } } 

then refer textbox external code this:

usercontrola.txtone.selectall(); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -