I am using random access and text files to store administrator details. Is there a way to just completely take all the data from the text file and format it in the data grid view instead of what I am doing which follows this procedure :
1) Search Admin ID
2) Outputs to textbox
3) Click "Add Admin to Datagrid view"
4) Shows the details there
this process is long winded and inefficient. Furthermore the records on the data grid are whipped and you have to re-add admins on the data grid when i stop debugging.
My question is
1) Is there a way of taking the data straight away from the text file and skipping the step of the procedure above and formatting it in the datagrid view
or
2) taking the procedure above but when I un debug the records can still be there ?
Code:Private Sub Administrator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load table.Columns.Add("AdminID", Type.GetType("System.String")) table.Columns.Add("Forename", Type.GetType("System.String")) table.Columns.Add("Surname", Type.GetType("System.String")) table.Columns.Add("Password", Type.GetType("System.String")) table.Columns.Add("Date Of Birth", Type.GetType("System.String")) table.Columns.Add("Contact Number", Type.GetType("System.String")) table.Columns.Add("Emergency Contact", Type.GetType("System.String")) table.Columns.Add("Address One", Type.GetType("System.String")) table.Columns.Add("Address Two", Type.GetType("System.String")) table.Columns.Add("PostCode", Type.GetType("System.String")) table.Columns.Add("Hour Salary", Type.GetType("System.String")) DataGridView1.DataSource = table End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_AddAdminDataGrid.Click table.Rows.Add(Tbx_AdminID.Text, Tbx_Forename.Text, Tbx_Surname.Text, Tbx_Password.Text, Tbx_DateOfBirth.Text, Tbx_ContactNumber.Text, Tbx_EmergencyContact.Text, Tbx_AddressOne.Text, Tbx_AddressTwo.Text, Tbx_PostCode.Text, Tbx_HourSalary.Text) DataGridView1.DataSource = table End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick Dim index As Integer index = e.RowIndex Dim selectedrow As DataGridViewRow selectedrow = DataGridView1.Rows(index) Tbx_AdminID.Text = selectedrow.Cells(0).Value.ToString() Tbx_Forename.Text = selectedrow.Cells(1).Value.ToString() Tbx_Surname.Text = selectedrow.Cells(2).Value.ToString() Tbx_Password.Text = selectedrow.Cells(3).Value.ToString() Tbx_DateOfBirth.Text = selectedrow.Cells(4).Value.ToString() Tbx_ContactNumber.Text = selectedrow.Cells(5).Value.ToString() Tbx_EmergencyContact.Text = selectedrow.Cells(6).Value.ToString() Tbx_AddressOne.Text = selectedrow.Cells(7).Value.ToString() Tbx_AddressTwo.Text = selectedrow.Cells(8).Value.ToString() Tbx_PostCode.Text = selectedrow.Cells(9).Value.ToString() Tbx_HourSalary.Text = selectedrow.Cells(10).Value.ToString() End Sub Private Sub Btn_UpdateAdmin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_UpdateAdmin.Click Dim newdatarow As DataGridViewRow newdatarow = DataGridView1.Rows(index) newdatarow.Cells(0).Value = Tbx_AdminID.Text newdatarow.Cells(1).Value = Tbx_Forename.Text newdatarow.Cells(2).Value = Tbx_Surname.Text newdatarow.Cells(3).Value = Tbx_Password.Text newdatarow.Cells(4).Value = Tbx_DateOfBirth.Text newdatarow.Cells(5).Value = Tbx_ContactNumber.Text newdatarow.Cells(6).Value = Tbx_EmergencyContact.Text newdatarow.Cells(7).Value = Tbx_AddressOne.Text newdatarow.Cells(8).Value = Tbx_AddressTwo.Text newdatarow.Cells(9).Value = Tbx_PostCode.Text newdatarow.Cells(10).Value = Tbx_HourSalary.Text End Sub




Reply With Quote
