I have a datagridview whose datasource is an entity collection.I can load the values of the selected rows into different textboxes using the datagridview SelectionChanged events.Below is the code that i am using.
Dim selectedUser = DirectCast(Me.grdShowOfficers.CurrentRow.DataBoundItem, Exams_Officer)
txtTitle.Text = selectedUser.Title
txtFirst.Text = selectedUser.First_Name
txtLastName.Text = selectedUser.Last_Name
txtFaculty.Text = selectedUser.Faculty.Faculty_Name
txtDepartment.Text = selectedUser.Department.Department_Name
txtProgramme.Text = selectedUser.Programme
txtPhoneNumber.Text = selectedUser.Phone_Number
dateAppointment.Text = selectedUser.Appointment_Date
It works fine.The problem is that when i change the values of the textbox it is not showing the edited values on the datagridview when i call the entity saveChanges() method from a button click event.I know i am doing something wrong please i need help.This is the button click event.
Dim selectedRow As Int32 = Me.grdShowOfficers.Rows.GetFirstRow(DataGridViewElementStates.Selected)
selectedrow.Title = txtTitle.Text
selectedUser.First_Name = txtFirst.Text
selectedUser.Last_Name() = txtLastName.Text
'selectedUser.Faculty.Faculty_Name = txtFaculty.Text
'selectedUser.Department.Department_Name = txtDepartment.Text
selectedUser.Programme = txtProgramme.Text
selectedUser.Phone_Number = txtPhoneNumber.Text
selectedUser.Appointment_Date = CType(dateAppointment.Text, Date)
examinationOfficer.SaveChanges()
when i do these (the below code ) on the datagridview contentdouble click event
txtTitle.Text = grdShowOfficers.Item("Title", grdShowOfficers.CurrentRow.Index).Value.ToString()
txtFirst.Text = grdShowOfficers.Item("First_Name", grdShowOfficers.CurrentRow.Index).Value.ToString()
txtLastName.Text = grdShowOfficers.Item("Last_Name", grdShowOfficers.CurrentRow.Index).Value.ToString()
txtProgramme.Text = grdShowOfficers.Item("Programme", grdShowOfficers.CurrentRow.Index).Value.ToString()
txtPhoneNumber.Text = grdShowOfficers.Item("Phone_Number", grdShowOfficers.CurrentRow.Index).Value.ToString()
dateAppointment.Text = grdShowOfficers.Item("Appointment_Date", grdShowOfficers.CurrentRow.Index).Value.ToString()
and this button click event before calling savechanges
grdShowOfficers.CurrentCell.Value = txtTitle.Text
grdShowOfficers.CurrentCell.Value = txtLastName.Text
grdShowOfficers.CurrentCell.Value = txtFirst.Text
grdShowOfficers.CurrentCell.Value = txtProgramme.Text
grdShowOfficers.CurrentCell.Value = txtPhoneNumber.Text
grdShowOfficers.CurrentCell.Value = dateAppointment.Text
only the first cell of the selected datagridview row is updated and the value it gets is the value of the last cell which is suppose to be updated by the dateappointment.text textbox.Please help