Click here to Skip to main content
15,902,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello... i want to know if it is possible to save the content of a datagridview into a file... also want to know how to load that file to my datagridview after closing it... thanks... it could be Vb.NET or C#
Posted

 
Share this answer
 
Comments
Monjurul Habib 8-Dec-11 15:47pm    
5!
I did this myself on the simple way:
VB
dim rows as integer = 'set rowcount
dim col as integer  = 'set column count     
dim regel1 as string = Nothing
For i = 0 To rows
   For j = 0 To columns
       regel1 += DataGridView1.Rows(i).Cells(j).Value + vbCrLf
   Next
Next
Dim objWriter20 As New System.IO.StreamWriter("somefile.txt")
objWriter20.WriteLine(regel1)
objWriter20.Close()


and read again:
VB
Infile = IO.File.OpenText("somefile.txt")
For i = 0 To rows
    For j = 0 To columns
      DataGridView1.Rows(i).Cells(j).Value = Infile.ReadLine()
    Next
Next
Infile.Close()
 
Share this answer
 
I got all over here

Let me know for further information.
 
Share this answer
 

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