Imports System.IO
Public Class AddEMForm
Private Sub CreateCSVfile(ByVal_strCustomerCSVPath As String, ByVal EName As String, ByVal Edate As Date, ByVal ELoc As String, ByVal EDis As String, ByVal EFee As String)
Try
Dim stLine As String = ""
Dim objWriter As StreamWriter = File.AppendText("..\..\EventData.txt")
If File.Exists("..\..\EventData.txt") Then
objWriter.Write(EName & ",")
objWriter.Write(Edate & ",")
objWriter.Write(ELoc & ",")
objWriter.Write(EDis & ",")
objWriter.WriteLine(EFee)
End If
objWriter.Close()
ClearTextbox()
Catch ex As Exception
End Try
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles LocTbx.TextChanged
End Sub
Private Sub AddEMForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Addbtn.Click
CreateCSVfile(Application.StartupPath & "\" & "Events.csv", NameTbx.Text.ToString(), DatePk.Text.ToString(), LocTbx.Text.ToString(), DisTbx.Text.ToString(), FeeTbx.Text.ToString())
End Sub
Private Sub ClearTextbox()
NameTbx.Text = ""
DatePk.Text = ""
LocTbx.Text = ""
DisTbx.Text = ""
NameTbx.Text = ""
FeeTbx.Text = ""
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Exitbtn.Click
ReadFile(Application.StartupPath & "\" & "Event.csv")
End Sub
Private Sub ReadFile(ByVal EventCSVPath As String)
Const Delim As String = ","
Dim stLine As String = ""
Dim objReader As New StreamReader("..\..\EventData.txt")
If File.Exists("..\..\EventData.txt") Then
Using objReader
While (objReader.EndOfStream) = False
EMForm.DataGridView1.Rows.Add(objReader.ReadLine().Split(Delim))
End While
End Using
objReader.Close()
End If
EMForm.Show()
Me.Close()
End Sub
Private Sub DisTbx_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DisTbx.SelectedIndexChanged
End Sub
Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click
End Sub
End Class
Here is what I trying do with this code:
•Enter event data on text field from a form and save it to a text file
•When I click exit the management form loads and extracts data from the text file and then display it on the data grid view
So far everything is working as listed above, However this is what I now want to do:
•When I select a record from the gridview, it should display on the text field of the form and allow me to change some data on the record and then update the change on the text file and display it on the gridview.
•Select a record from gridview and delete it by clicking the delete button