Click here to Skip to main content
15,908,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :

VB
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.
Posted
Updated 30-Jul-12 9:57am
v4
Comments
Simon_Whale 26-Jul-12 6:13am    
How are the records in the datagridview? dataset, list etc?
RuchitaGavali 26-Jul-12 6:57am    
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.

To store data in Datagridview I used Data table.
AshishChaudha 26-Jul-12 6:37am    
Could you please show us what you have done??? and where you got stuck??
RuchitaGavali 26-Jul-12 6:55am    
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
Maciej Los 26-Jul-12 17:09pm    
What have you done till now?

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900