日期:2014-05-18 浏览次数:20870 次
//向DGV添加行 private void pos_main_Load(object sender, EventArgs e) { DataGridViewCheckBoxColumn newcolumns = new DataGridViewCheckBoxColumn(); newcolumns.HeaderText = "选择"; this.data_list.Columns.Add("1", "货号"); this.data_list.Columns.Add("2", "品名"); this.data_list.Columns.Add("3", "产地"); this.data_list.Columns.Add("4", "规格"); this.data_list.Columns.Add("5", "单位"); this.data_list.Columns.Add("6", "零售价"); this.data_list.Columns.Add("7", "数量"); this.data_list.Columns.Add(newcolumns); this.data_list.Columns[0].Width = 90; this.data_list.Columns[1].Width = 180; this.data_list.Columns[2].Width = 90; this.data_list.Columns[3].Width = 90; this.data_list.Columns[4].Width = 58; this.data_list.Columns[5].Width = 90; this.data_list.Columns[6].Width = 62; this.data_list.Columns[7].Width = 50; ; }
For index = 0 To detailList.Count - 1 Dim cellCheckBox1 As DataGridViewCheckBoxCell = New DataGridViewCheckBoxCell cellCheckBox1.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DgvSekisanItiran.Rows(index).Cells(7) = cellCheckBox1 Next
------解决方案--------------------
判断那一列每个单元格的值,因为checkbox返回值是1或0或null
ok,如果是1,就删除为1的行就好了.
用vb.net写法
for i as integer dgv.rows.count-2 to 0 step -1 'gv.rows.count-2是除去那个动态添加行 if dgv.rows(i).cells(7).formattedvalue=1 then '用formattedvalue属性直接可以可以去除null的判断 dgv.rows.removeat(i) end if next