i'm using visual studio 2012 and SQL server 2012 to make form to copy data in datagridview to another datagridview.
this is my coding:
Public Class Form3
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.AllowUserToAddRows = False
DataGridView2.AllowUserToAddRows = False
ClassKoneksi.namadatabase = "KPIRWAN"
Dim dssiswa As New DataSet
Dim sql As String
sql = "select*from Siswa order by NIS ASC"
dssiswa = ClassSiswa.displayData(ClassSiswa.opencon, sql, "DataSiswa")
DataGridView1.DataSource = dssiswa
DataGridView1.DataMember = "DataSiswa"
DataGridView1.ReadOnly = True
DataGridView2.ColumnCount = DataGridView1.ColumnCount
For a = 0 To DataGridView1.ColumnCount
DataGridView2.Columns(a).Name = DataGridView1.Columns(a).Name
Next a
ClassSiswa.closecon()
End Sub
Private Sub ButtonCopy_Click(sender As Object, e As EventArgs) Handles ButtonCopy.Click
Dim dr As New System.Windows.Forms.DataGridViewRow
For Each dr In Me.DataGridView1.SelectedRows
Me.DataGridView2.Rows.Add(dr.Cells(0).Value,
dr.Cells(1).Value,
dr.Cells(2).Value,
dr.Cells(3).Value,
dr.Cells(4).Value,
dr.Cells(5).Value)
Next
End Sub
Private Sub ButtonDel_Click(sender As Object, e As EventArgs) Handles ButtonDel.Click
Dim LastRow As DataGridViewRow = (From this In DataGridView2.Rows.OfType(Of DataGridViewRow)() Where Not this.IsNewRow).LastOrDefault
If LastRow IsNot Nothing Then
DataGridView2.Rows.Remove(LastRow)
End If
End Sub
End Class
the function of this form is:
- button "copy" is used to copy the row from the top datagridview to the bottom datagridview.
- using button "delete" the row in the bottom datagridview will be removed.
the problem is:
after i copy the row in the top datagridview to the bottom datagridview i closed the form.but,after i run the program again the row in the bottom datagridview disappear.
what i want is to create a save function using button save so that after i copied the row on the top datagridview to the bottom datagridview, the row in the bottom datagridview will stay there when i running the program again.
how do i create a coding to do that?