[英]ArgumentOutOfRangeException when writing C# List<string> to multiple textbox
How to put list to multiple TextBoxes? 如何将列表放到多个TextBoxes? I have tried to use several way to do it.
我试图用几种方法来做到这一点。 All of them can put only one value from
List<string>
into TextBox and show an error of System.ArgumentOutOfRangeException
它们都只能将
List<string>
一个值放入TextBox中,并显示System.ArgumentOutOfRangeException
错误
Below is the code I have tried this far: 下面是到目前为止我尝试过的代码:
List<string> txtlist = new List<string>();
for (int ix = 1; ix < 16; ix++)
{
string test = command.Get(appendCommand);
txtlist.Add(test);
txt_1.Text = txtlist.ElementAt(0);
txt_2.Text = txtlist.ElementAt(1); //System.ArgumentOutOfRangeException
txt_3.Text = txtlist.ElementAt(2);
txt_4.Text = txtlist.ElementAt(3);
...
txt_4.Text = txtlist.ElementAt(15);
}
List txtlist data show as below: 列表txtlist数据显示如下:
[0] "test1" [1] "test2" [2] "test3" .... [15] "test16"
[0]“ test1” [1]“ test2” [2]“ test3” .... [15]“ test16”
I want to put list one by one to the textbox, please show me some example, thank you. 我想一一列出到文本框中,请给我看一些例子,谢谢。
First build txtList and after that there are items to get. 首先建立txtList,然后建立项目。 No more
ArgumentOutOfRangeException
不再有
ArgumentOutOfRangeException
List<string> txtlist = new List<string>();
for (int i = 0; i < 16; i++)
{
string test = command.Get(appendCommand);
txtlist.Add(test);
}
txt_1.Text = txtlist.ElementAt(0);
txt_2.Text = txtlist.ElementAt(1);
txt_3.Text = txtlist.ElementAt(2);
txt_4.Text = txtlist.ElementAt(3);
...
txt_4.Text = txtlist.ElementAt(15);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.