I’m new windows phone, I want to create a textbox one by one inside the grid using for loop dynamically. and i want to access the textboxes using their names to perform some calculations. my code is shown below:
public MainPage()
{
InitializeComponent();
string[] str = new string[2];
str[0] = "force";
str[1] = "force components";
TextBox[] textbox = new TextBox[2];
for (int i =0; i <2; i++)
{
textbox[i].Text = str[i];
ContentPanel.Children.Add(textbox[i]);
}
}
the above code shows null reference exception in the line “textbox[i].Text = str[i]”.
please, show me the code for clearing this issue. help me. Thank You..
I’m not entirely convinced you’re doing this the right way*, but in the absense of any better information I’ll directly answer your question…
You’re not declaring a new TextBox for each iteration of the loop. Try this…
* Binding to an ItemsControl of some sort would probably be preferable…