Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,
I tried to insert the column name from datagridview1 to rows of datagridview2 and that was work, but the first row problem. when moving the mouse to the end position and back to the first position, the value does not appear.
Thanks for your help
http://img10.imageshack.us/img10/617/xtv9.png[^]
VB
Private Sub DataGridView1_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
       Try
           For srow As Integer = 0 To DataGridView1.Rows.Count - 1
               If DataGridView2.Rows.Count > 1 And DataGridView2.Rows(0).Cells(0).Value = DataGridView1.Columns(0).HeaderText Then
                   DataGridView2.Rows.Clear()
               ElseIf DataGridView1.Rows(srow).Selected Then
                   DataGridView1.Rows(srow).Selected = True
                   Dim col1 As String = DataGridView1.Columns(0).HeaderText
                   Dim row1 As String = DataGridView1.Rows(srow).Cells(0).Value
                   DataGridView2.Rows.Add(col1, row1)
                   Dim col2 As String = DataGridView1.Columns(1).HeaderText
                   Dim row2 As String = DataGridView1.Rows(srow).Cells(1).Value
                   DataGridView2.Rows.Add(col2, row2)
                   Dim col3 As String = DataGridView1.Columns(2).HeaderText
                   Dim row3 As String = DataGridView1.Rows(srow).Cells(2).Value
                   DataGridView2.Rows.Add(col3, row3)
                   Dim col4 As String = DataGridView1.Columns(3).HeaderText
                   Dim row4 As String = DataGridView1.Rows(srow).Cells(3).Value
                   DataGridView2.Rows.Add(col4, row4)

                   Return
               End If
           Next
       Catch ex As Exception

       End Try
   End Sub
Posted

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