删除datagridview中选中的行 [英] delete the checked rows in a datagridview

查看:91
本文介绍了删除datagridview中选中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是vb.net 2008的新手.在datagridview中,我添加了带有复选框的列.我只需要一个代码即可删除选中的行.
非常感谢.

Hi,

I am new to vb.net 2008. In a datagridview I added a column with checkboxes. I need a code to delete the checked rows only.
Many thanks.

推荐答案

为什么要使用"dt".它是一个局部声明的变量.不是吗?
Why are you using "dt". It is a locally declared variable. Isn''t it?
For x As Integer = DataGridView1.Rows.Count - 1 To 0 Step -1
  If DataGridView1.Rows(x).Cells("checked").Value Then
    DataGridView1.Rows.Remove(DataGridView1.Rows(x))
  End If
Next



要删除选中的行,

例如dtTable是绑定gridview的数据表.
Hi,
To delete The checked Rows,

For example dtTable is the datatable that bind gridview.
gridview1.datasource=dtTable.


首先在表格中找到已检查"项目,


First find the Checked item in the table,

For i=0 to dtTable.Rows.Count-1

      if dtTable.Rows(i).Item("Checked")=true then
          gridview1.rows.removeat(i)
     end if
next




问候
Sreyas MN




Regards
Sreyas MN


基本上,您可以循环浏览各行,并删除选中该复选框的行.如果按索引号排序,请从末尾开始,这样未处理的索引号就不会改变位置.

到目前为止,您尝试了哪些无效的方法?
Basically you can loop through the rows and delete the ones that have the checkbox checked. If you go by index numbers, start from the end so the ones you haven''t processed don''t change position.

What have you tried so far that doesn''t work?


这篇关于删除datagridview中选中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆