Tuesday, 15 July 2014

c# - Cannot reference dynamically referenced controls -


I am using the instructions available to access some textboxes which are already in my < Code> Winform . For some reason I get an error:

The object reference is not set to an instance of an object

I'm pretty sure the code is correct But as soon as I try to reach any property of the control, I get the error. My code is below - is anyone doing me wrong, how can I find it?

  textbox text box = this. Control ["txtLiveBlock" + ((i + 1) * (j + 1)). ToString ()] as text box; Textbox.Text = "test";   

Note that my textbox is called "txtLiveBlock1" and i = 0, j = 0. I also tried to send txtLiveBlock "+ ((I + 1) * (j + 1) to a message box and get me back" txtLiveBlock1 ". < / P>

Enter image details here

If the control is within another container control, such as a panel or tab page, you must specify that container control:

  Textbox Text Box = Tab Page 1. Control ["txtLiveBlock" + ((i + 1) * (J + 1)). Tooth Texting as text box; text box. Text = "test";    

No comments:

Post a Comment