public void test() { List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); for (int i = 1; i <= list.Count; i++) { textBx.Text = list[i].ToString(); // I want it to be textBx1.Text = list[1].ToString(); textBx2.Text = list[2].ToString(); textBx3.Text = list[3].Tostring(); etc. // I can't create textbox dynamically as I need the text box to be placed in specific places in the form . How do I do it the best way? } }
public void test() { List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); for (int
Share
Sounds like a job for Controls.Find(). You could dynamically build your string and search for the TextBox with that name:
This is a bit ugly as it’s predicated on your naming convention for the TextBoxes. Perhaps a better solution would be to cache a list of the TextBoxes before your loop:
Then you can simply index into the array: