Save DataGridView to Text file,CSV file

Tháng Chín 12, 2008 at 1:03 sáng Để lại phản hồi

Public Sub SaveGridDataInFile(ByRef fName As String, ByVal ExDataGrid As DataGridView)
Dim I As Integer = 0
Dim j As Integer = 0
Dim cellvalue As String
Dim rowLine As String = “”
Try
Dim objWriter As New System.IO.StreamWriter(fName, True, System.Text.Encoding.Default)

For I = 0 To ExDataGrid.Columns.Count – 1
rowLine = rowLine & ExDataGrid.Columns(I).Name & “,”
Next
rowLine = rowLine.Remove(rowLine.Length – 1, 1)
objWriter.WriteLine(rowLine)
rowLine = “”
For j = 0 To (ExDataGrid.Rows.Count – 1)
For I = 0 To (ExDataGrid.Columns.Count – 1)
cellvalue = ExDataGrid.Item(I, j).Value.ToString
rowLine = rowLine + Chr(34) & cellvalue & Chr(34) + “,”
Next
rowLine = rowLine.Remove(rowLine.Length – 1, 1)
objWriter.WriteLine(rowLine)
rowLine = “”
Next
objWriter.Close()
objWriter.Dispose()
ExDataGrid.AllowUserToAddRows = True
MsgBox(“保存ファイル成功”)
Catch
End Try

End Sub

Entry filed under: VB.NET. Tags: .

Read Text file, CSV file to DataGridView Add Rows Number to DataGridView

Gửi phản hồi

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Thay đổi )

Twitter picture

You are commenting using your Twitter account. Log Out / Thay đổi )

Facebook photo

You are commenting using your Facebook account. Log Out / Thay đổi )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


 

Tháng Chín 2008
T2 T3 T4 T5 T6 T7 CN
« Tháng 8   Tháng 10 »
1234567
891011121314
15161718192021
22232425262728
2930  

Follow

Get every new post delivered to your Inbox.