System.Collections.ArrayList s1 = new System.Collections.ArrayList();
for (int i = 0; i < dataGridView1.Rows.Count; i++)//循环dataGridView1的行
{
s1.Add(dataGridView1.Rows[i].Cells[0].Value.ToString ());//将dataGridView1中的第一列存入s1中
}
出现未处理的“System.NullReferenceException”类型的异常出现在 GND_GearCNC.exe 中。
其他信息: 未将对象引用设置到对象的实例。
dataGridView1.Rows[i].Cells[0].Value.ToString,首先保证这句代码中,各个对象不能为null,特别注意带索引的,然后将之ToString后添加到数组就行了,如果你添加到List,那么可以最后ToArray
楼主 你可以把dataGridView1.Rows[i].Cells[0].Value.ToString () 打印一下 看看 是不是 报异常
集合添加元素 这个 应该不会出现异常 只能是数据的问题