日期:2014-05-18 浏览次数:20766 次
DataTable dt; private void Form1_Load(object sender, EventArgs e) { dt = new DataTable(); dt.Columns.Add(new DataColumn("id")); dt.Columns.Add(new DataColumn("name")); DataRow dr = null; dr = dt.NewRow(); dr["id"] = "001"; dr["name"] = "Name1"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["id"] = "002"; dr["name"] = "Name2"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["id"] = "001"; dr["name"] = "Name1"; dt.Rows.Add(dr); //dt.TableNewRow += new DataTableNewRowEventHandler(dt_NewTableRow); dataGridView1.DataSource = dt; } bool flag = true; private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e) { if (flag == false) dt.Rows.RemoveAt(e.RowIndex); flag = false; }
------解决方案--------------------
应该尽量从客户端控制其写入数据库中的数据的有效性!