首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

datagridview 起用添加

2013-01-11 
datagridview 启用添加datagridview1 里1:有 A , B 两个域2:没有绑定数据源3:datagridview1 启用添加 运行

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 

热点排行