Click here to Skip to main content
11,490,282 members (54,556 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I made a programmed to Transfer Employee's To Other Company Therefore I used Two DataGridView, In First DataGridView Component I Bind it with database and Add One Another columns, and it's a checkboxcolumn,
Now I want to Copy/Transfer Rows From One DataGridView1 To DataGridView2 When I Tick or Checked; ChecekColumnBox in First DataGridView1.
Posted 12-Feb-13 21:54pm
Remoddn1.1K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I got It........
I made New and success in datagridview1 rows copy to another datagridview2 in vb.net

below is a code on button12_click Event

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
 
        Dim c, t As Integer
        dg2.Columns.Clear()
 
        For t = 0 To dg1.Columns.Count - 1
            dg2.Columns.Add(dg1.Columns(t).Clone())
        Next
 
        For c = 0 To dg1.Rows.Count - 1
       
     If dg1.Rows(c).Cells(4).Value = True Then
                dg2.Rows.Add(dg1.Rows(c).Cells(0).Value, dg1.Rows(c).Cells(1).Value)
                dg2.Columns(2).Visible = False
                dg2.Columns(3).Visible = False
       
     End If
 
        Next
    End Sub
Use it..............

[edit]code blocks added[/edit]
  Permalink  
v2
Comments
Nelek at 13-Feb-13 3:10am
   
Self-solved in the same minute of the question.... that was fast :)
Remoddn at 13-Feb-13 3:29am
   
Yes! Nelek Because of I m trying or finding this question's answer but unable to find therefore today I create and find solution so; I post both of them, i.e. question's with answer.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Dim c, t As Integer
     DataGridView2.Columns.Clear()
 
     For t = 0 To DataGridView1.Columns.Count - 1
         DataGridView2.Columns.Add(DataGridView1.Columns(t).Clone())
     Next
 
     For c = 0 To DataGridView1.Rows.Count - 1
 
         If Not IsDBNull(DataGridView1.Rows(c).Cells(3).Value) Then
             DataGridView2.Rows.Add(DataGridView1.Rows(c).Cells(0).Value, DataGridView1.Rows(c).Cells(1).Value, DataGridView1.Rows(c).Cells(2).Value, DataGridView1.Rows(c).Cells(3).Value)
             ' DataGridView2.Columns(2).Visible = False
             ' DataGridView2.Columns(3).Visible = False

         End If
 
     Next
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 650
1 Andy Lanng 233
2 OriginalGriff 188
3 Sascha Lefèvre 170
4 Maciej Los 160
0 Sergey Alexandrovich Kryukov 9,713
1 OriginalGriff 8,475
2 Sascha Lefèvre 3,504
3 Maciej Los 3,106
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 19 Aug 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100