繁体   English   中英

编写C#列表时出现ArgumentOutOfRangeException <string> 到多个文本框

[英]ArgumentOutOfRangeException when writing C# List<string> to multiple textbox

如何将列表放到多个TextBoxes? 我试图用几种方法来做到这一点。 它们都只能将List<string>一个值放入TextBox中,并显示System.ArgumentOutOfRangeException错误

下面是到目前为止我尝试过的代码:

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);
}

列表txtlist数据显示如下:

[0]“ test1” [1]“ test2” [2]“ test3” .... [15]“ test16”

我想一一列出到文本框中,请给我看一些例子,谢谢。

首先建立txtList,然后建立项目。 不再有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM