Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ArgumentOutOfRange写入C#列表时出现异常<;字符串>;到多个文本框_C#_Winforms - Fatal编程技术网

ArgumentOutOfRange写入C#列表时出现异常<;字符串>;到多个文本框

ArgumentOutOfRange写入C#列表时出现异常<;字符串>;到多个文本框,c#,winforms,C#,Winforms,如何将列表放入多个文本框?我试过用几种方法来做这件事。它们都只能将列表中的一个值放入文本框,并显示系统的错误。ArgumentOutOfRangeException List<string> txtlist = new List<string>(); for (int i = 0; i < 16; i++) { string test = command.Get(appendCommand); txtlist.Add(test); } txt_1.Te

如何将列表放入多个文本框?我试过用几种方法来做这件事。它们都只能将
列表
中的一个值放入文本框,并显示
系统的错误。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);
以下是我迄今为止尝试过的代码:

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=new List();
对于(int-ix=1;ix<16;ix++)
{
string test=command.Get(appendCommand);
txtlist.Add(测试);
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] “测试16”


我想把列表一个接一个地放到文本框中,请给我看一些例子,谢谢。

首先构建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);
List txtlist=new List();
对于(int i=0;i<16;i++)
{
string test=command.Get(appendCommand);
txtlist.Add(测试);
}
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);

ArgumentOutOfRangeException
如果我有一个苹果,你要第二个,会发生什么。现在,您需要做的是调试代码并找出原因。。。你加上1个项目,然后要求接下来的16个项目,这没有意义。你想达到什么目的?是否要将列表中的每个项目绑定到每个文本框,或将列表中的所有项目绑定到所有文本框?@Victor您正在创建一个
新列表()
,并且在循环中只添加一个项目。所以它无法获得其他项目。为避免此错误,您必须在完成循环后将文本添加到
textBox
。@er sho yes我想将所有项目绑定到不同的textbox@Victor那么,有什么标准可以约束呢?表示所有项目都以逗号分隔或任何格式绑定?没问题。顺便说一句,我没有得到“列表数据”部分的问题描述-你必须详细阐述你的问题在这一部分。。或者如果去掉ArgumentOutOfRangeException就足够了,你可以接受这个答案。很抱歉,我已经更新了这个问题。太困会犯很多疯狂的错误。我会休息一下,然后再回到代码。好的,让我们结束这个。如果出现新问题,休息后你可以再问一个问题。。