DataTable dt2 = ht["多收费记录"] as DataTable;
for (int i = 0; i < dt2.Rows.Count; i++)
{
DataGridViewRow row = new DataGridViewRow();
this.DataGridView1.Rows.Add(row);
row.Cells["yhdm"].Value = dt2.Rows[i]["bank_id"].ToString();
row.Cells["lsbh"].Value = dt2.Rows[i]["id"].ToString();
row.Cells["rq"].Value = dt2.Rows[i]["tpdate"].ToString();
row.Cells["ss"].Value = dt2.Rows[i]["realpay"].ToString();
row.Cells["khh"].Value = dt2.Rows[i]["custid"].ToString();
row.Cells["khdbh"].Value = dt2.Rows[i]["client"].ToString();
row.Cells["qqm"].Value = dt2.Rows[i]["reqcode"].ToString();
}
我的代码是这样的,其中dt2中有200多行数据,在for循环加载时候,i=0的时候,可以通过,当i=1的时候,就报错了
提示指定的参数已超出有效值的范围。参数名: rowIndex
row.Cells["yhdm"].Value 引发了System.ArgumentOutOfRangeException异常
解决方案 »
- 求助怎么写个自动生成订单的函数
- c# 制作的程序需要sql express支持,我把sql支持做到一个安装包里去,出现问题,求助
- C#关于子窗体和菜单的问题???
- 想给MS一些建议怎么才能够发给他们啊
- c#怎样数据库中某一条数据在数据库中的位置传递给CurrencyManager.Position
- 怎么解决DataGridView控件的绘制错误啊?高手们。来帮帮忙
- .net操作oracle数据库的一个问题,高手请进
- 急救:关于RichTextBox控件如何使每一行的字体,颜色都不一样
- 如果网络设置了代理,调用WCF如何设置?
- 请高手点评一下这个ASP.NET 论坛系统 全球首个同时支持多形象的Avatar系统
- 历遍硬盘上的所有文件(在WINFORM上)
- C#按钮第三方控件!!
this.dgv.Rows.Add(); //添加空行
//设置新添空行值
this.dgv.Rows[i].Cells[1].Value="";
DataGridViewRow row = new DataGridViewRow();
row.Cells["yhdm"].Value = dt2.Rows[i]["bank_id"].ToString();
row.Cells["lsbh"].Value = dt2.Rows[i]["id"].ToString();
row.Cells["rq"].Value = dt2.Rows[i]["tpdate"].ToString();
row.Cells["ss"].Value = dt2.Rows[i]["realpay"].ToString();
row.Cells["khh"].Value = dt2.Rows[i]["custid"].ToString();
row.Cells["khdbh"].Value = dt2.Rows[i]["client"].ToString();
row.Cells["qqm"].Value = dt2.Rows[i]["reqcode"].ToString();
this.DataGridView1.Rows.Add(row);
换个顺序试试
for (int i = 1; i < dt2.Rows.Count; i++)
{
DataGridViewRow row = new DataGridViewRow();
this.DataGridView1.Rows.Add(row);
row.Cells["yhdm"].Value = dt2.Rows[i-1]["bank_id"].ToString();
row.Cells["lsbh"].Value = dt2.Rows[i-1]["id"].ToString();
row.Cells["rq"].Value = dt2.Rows[i-1]["tpdate"].ToString();
row.Cells["ss"].Value = dt2.Rows[i-1]["realpay"].ToString();
row.Cells["khh"].Value = dt2.Rows[i-1]["custid"].ToString();
row.Cells["khdbh"].Value = dt2.Rows[i-1]["client"].ToString();
row.Cells["qqm"].Value = dt2.Rows[i-1]["reqcode"].ToString();
}