03-04-16, 09:55 AM
(03-04-16, 08:03 AM)الماجيك مسعد كتب :كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
savedata(DataGridView1, "myfile.txt")
loaddata("myfile.txt", DataGridView2)
End Sub
Sub savedata(ByVal dg As DataGridView, ByVal filename As String)
Dim mSB As New System.Text.StringBuilder
For Each mRow As DataGridViewRow In dg.Rows
mSB.AppendLine(String.Join(vbTab, From mCell In mRow.Cells Select mCell.Value))
Next
IO.File.WriteAllText(filename, mSB.ToString)
End Sub
Sub loaddata(ByVal filename As String, ByVal dg As DataGridView)
For Each mLN As String In IO.File.ReadLines(filename)
dg.Rows.Add(mLN.Split(vbTab))
Next
End Sub
