saving a csv file on a datagrid view

jsalzm1

Member
Join Date
Jun 2015
Location
Houston
Posts
23
'Code to save data
Dim csvFile As String = My.Application.Info.DirectoryPath & "\HoseData.csv"

Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, True)

'If My.Computer.FileSystem.FileExists(csvFile) Then
'outFile.WriteLine("job number, sales order number, date, requested by, serial number, hose type, hose size, fitting 1, fitting 2, qty, oal, cut off, offset, crimp 1, crimp 2, cleaned, pigged", False)
' End If

outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """" & "," & ComboBox1.Text & "," & TextBox3.Text & "," & ListBox2.Text & "," & ListBox3.Text & "," & TextBox11.Text & "," & TextBox12.Text & "," & NumericUpDown1.TextAlign & "," & TextBox4.Text & "," & TextBox5.Text & "," & TextBox6.Text & "," & TextBox9.Text & "," & TextBox10.Text & "," & ListBox4.Text & "," & ListBox5.Text)
MessageBox.Show("INPUT WAS SAVED")

Dim butt As System.Windows.Forms.Button = DirectCast(sender, System.Windows.Forms.Button)

'butt.Enabled = False

'butt.Visible = False

outFile.Close()

TextBox1.Text = ""
TextBox2.Text = ""
DateTimePicker1.Text = ""
If ComboBox1.Items.Count > 0 Then
ComboBox1.SelectedIndex = 0 ' The first item has index 0 '
End If
TextBox3.Text = ""
ListBox2.ClearSelected()
ListBox3.ClearSelected()
TextBox11.Text = ""
TextBox12.Text = ""
NumericUpDown1.Value = 0
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
ListBox4.ClearSelected()
ListBox5.ClearSelected()

Console.WriteLine(My.Computer.FileSystem.ReadAllText(csvFile))

'code to load data into datagridview1

Dim TextFieldParser1 As New Microsoft.VisualBasic.FileIO.TextFieldParser("HoseData.csv")

TextFieldParser1.Delimiters = New String() {","}

While Not TextFieldParser1.EndOfData
Dim Row1 As String() = TextFieldParser1.ReadFields()

If DataGridView1.Columns.Count = 0 AndAlso Row1.Count > 0 Then
Dim i As Integer

For i = 0 To Row1.Count - 1
DataGridView1.Columns.Add("Column" & i + 1, "Column" & i + 1)
Next
End If
DataGridView1.Rows.Add(Row1)
End While

Button1.Enabled = False
 

Similar Topics

Hi all, I need to save tag info for time, date, and a few product specifications every time an operator hits a crash button. We are attempting to...
Replies
7
Views
3,084
Hi all, Last question I have and I think my program will be complete! Please help! So far I have gotten the csv file to read to excel and I am...
Replies
2
Views
1,500
Hi everyone, i have an issue with saving a changed value in an AOI, I am using L84E, Everytime i try to save my work to SD card, the program lost...
Replies
1
Views
92
Hi all, I have installed a SICK AFM60A-S4IB018x12 encoder to Allen-Bradley CompactLogix PLC and configured its parameters via AOI provided by...
Replies
0
Views
93
Hello, i have a problem, i was trying to fix a trend that wasn't registering the tags, i got that fix by setting the path, but now i can get it to...
Replies
2
Views
828
Back
Top Bottom