转移选定的记录 [英] transfer selected records

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

问题描述

如何在VB.NET中将所选记录(使用复选框选中)从一个datagridview传输到另一个datagridview


我在第一列中有一个带复选框的Datagridview,如果有10条记录,而我在Datagridview中使用复选框仅选择了5条记录,则在按钮的单击事件上它会在第二个Datagridview中被查看

我卡住的代码:

How do i transfer selected records(selected using check box) from one datagridview to another datagridview in VB.NET


I have one Datagridview with checkbox in 1st column, if there are 10 records and I select only 5 records using checkbox in Datagridview, on the click event of button it gets viewed in 2nd Datagridview

The code where i stuck :

For j As Integer = 0 To DataGridView2.Rows.Count - 1 
    If CBool(DataGridView2.Rows(j).Cells(1).Value) = True Then 
        Dim r As Form1.DataGridView2.Rows.count
        Form1.DataGridView2.Rows(r-1).Cells(0).Value = DataGridView2.Rows(j).Cells(0).Value 
    End If 
Next


它显示了无法使用编程插入数据的异常.


It shows exception that data can not be inserted using programming.

推荐答案

在按钮click事件上,使用数据表dt = gridview1.datasource;.这将为您提供第一个gridview的数据.之后,您可以进行循环检查是否选中了特定的行.如果不这样做,请从数据表中删除该行.然后将该数据表分配给第二个gridview

希望对您有帮助.
on the button click event , take the datatable dt=gridview1.datasource; which will give you the data of first gridview. After that you can do a loop in which you can check whether a particular row is selected or not.If not than remove that row from your datatable.After that assign this datatable to your second gridview

Hope this helps you.


这篇关于转移选定的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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