Below is my code
Private dtable As DataTable = New DataTable()
Private lstName As List(Of String) = New List(Of String)()
Private control As Boolean = True
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim name As String = DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).HeaderText
If Not lstName.Contains(name) Then
lstName.Add(name)
dtable.Columns.Add(name)
If control Then
For x As Integer = 0 To DataGridView1.Rows.Count - 1 - 1
Dim s As String = DataGridView1.Rows(x).Cells(DataGridView1.CurrentCell.ColumnIndex).Value.ToString()
dtable.Rows.Add(s)
Next
control = False
Else
For y As Integer = 0 To dtable.Rows.Count - 1
dtable.Rows(y)(name) = DataGridView1.Rows(y).Cells(DataGridView1.CurrentCell.ColumnIndex).Value.ToString()
Next
End If
End If
DataGridView2.DataSource = dtable
End Sub
dtable.Clear()
lstName.Clear()
program current status
after clear database datagridview 2 still no clear complete