本文介绍了ArgumentOutOfRangeException是未处理的C#。参数名称:index的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! ArgumentOutOfRangeException是未处理的C#。参数名称:索引 这里是我的代码ArgumentOutOfRangeException was Unhandled C#. Parameter name: indexhere is my codeif (lvnames.Items.Count > 0) { for (int x = 0; x < lvnamestemp.Items.Count; x++) { lvnames.Items[x].SubItems[4].Text = lvnamestemp.Items[x].SubItems[0].Text; } } else { MessageBox.Show("No Record", "Empty", MessageBoxButtons.OK, MessageBoxIcon.Information); } 我的水晶报告也是and for my crystal report alsoDataSet ds = new DataSet(); DataTable t = ds.Tables.Add("Record"); t.Columns.Add("Name", Type.GetType("System.String")); t.Columns.Add("Age", Type.GetType("System.String")); t.Columns.Add("Address", Type.GetType("System.String")); t.Columns.Add("Tel Number", Type.GetType("System.String")); t.Columns.Add("School", Type.GetType("System.String")); DataRow r; foreach (ListViewItem LVI in lvnames.Items) { r = t.NewRow(); r["Name"] = LVI.SubItems[0].Text; r["Age"] = LVI.SubItems[1].Text; r["Address"] = LVI.SubItems[2].Text; r["Tel Number"] = LVI.SubItems[3].Text; r["School"] = LVI.SubItems[4].Text; t.Rows.Add(r); } 我的lvnames.Items有5个列,我的lvnamestemp有3列 i得到了这个错误InvalidArgument =当我运行代码时值为'4' i尝试在我的lvnames上添加5列但仍然出现无效参数 请给我一些想法,找出简单的解决方案,并在C#语言my lvnames.Items has 5 colums and my lvnamestemp has 3 columnsi got that error InvalidArgument=Value of '4' when i run the codei tried to add 5 columns on my lvnames but still invalidargument appearsplease give me some sort of ideas to figure out the simple solution and im new at C# language推荐答案lvnames.Items[x].SubItems[4].Text = lvnamestemp.Items[x].SubItems[0].Text; 您的错误是抱怨4是无效值,所以我首先看一下lvnames子项参数,因为它总是4 ... 使用调试器,或者在发生异常时,或者通过放入断点并查看确切的内容数据看起来像。你有没有子项目?如果是这样,有多少?可能你有4个子项,这意味着当我删除LVI.Subitems [3]和LVI.Subitems [4] $ b时应该是3 ...Your error is complaining that "4" is an invalid value, so I'd start by looking at the lvnames subitems parameter, since that is always 4...Use the debugger, either when the exception occurs, or by putting a breakpoint in and look at exactly what your data looks like. Have you got any subitems? If so, how many? Probably, you have 4 subitems, which means that should be 3...DataSet ds = new DataSet(); DataTable t = ds.Tables.Add("Record"); t.Columns.Add("Name", Type.GetType("System.String")); t.Columns.Add("Age", Type.GetType("System.String")); t.Columns.Add("Address", Type.GetType("System.String")); t.Columns.Add("Tel Number", Type.GetType("System.String")); t.Columns.Add("School", Type.GetType("System.String")); DataRow r; foreach (ListViewItem LVI in lvnames.Items) { r = t.NewRow(); r["Name"] = LVI.SubItems[0].Text; r["Age"] = LVI.SubItems[1].Text; r["Address"] = LVI.SubItems[2].Text; t.Rows.Add(r); } 并更改lvnames.Items [x] .SubItems [4]。文本到lvnames.Items [x] .SubItems [2] .Text 它没有显示错误并且运行流畅并且在我的报表查看器上显示为 姓名: 年龄: 地址: 但我在lvnames中有4个子项目,我想在水晶报告中查看.. 喜欢这个 姓名: 年龄: 地址: 电话号码: 学校: 我该怎么办.. ??and change lvnames.Items[x].SubItems[4].Text into lvnames.Items[x].SubItems[2].Textit shows no error and run smoothly and displays on my report viewer asName:Age:Address:but i do have 4 subitems in lvnames which i want to be viewed in crystal report..like thisName:Age:Address:Tel Number:School:what should i do..?? 这篇关于ArgumentOutOfRangeException是未处理的C#。参数名称:index的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-07 23:30