datagridview 启用添加
datagridview1 里
1:有 A , B 两个域
2:没有绑定数据源
3:datagridview1 启用添加
运行后 我往里面添加了记录
有个按钮点击事件里
string ls="";
if (dataGridView1.Rows.Count > 0)
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
ls += dataGridView1.Rows[i].Cells["A"].Value.ToString().Trim();
}
ls += dataGridView1.Rows[i].Cells["A"].Value.ToString().Trim();
这句报错:
未处理 System.NullReferenceException
{"未将对象引用设置到对象的实例。"}
[解决办法]
string ls="";
if (dataGridView1.Rows.Count > 0)
for (int i = 0; i < dataGridView1.Rows.Count -1; i++)
{
ls += dataGridView1.Rows[i].Cells["A"].Value.ToString().Trim();
}
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
有新行 要减 1