Click here to Skip to main content
15,916,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

SQL
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)

SQL
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
VB
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
VB
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
Posted
Updated 6-Jun-13 23:01pm
v4
Comments
Nelek 7-Jun-13 4:10am    
Please use the "Improve question" widget and add the snippet of the button where you call the saveChanges. It might give some information about what you are missing
Surendra Adhikari SA 7-Jun-13 4:25am    
did you got any error?? debug through the code and give detail of debugging . that may help.
jamiebones 7-Jun-13 4:47am    
No error just not working

1 solution

In your button click event you are using
VB
grdShowOfficers.CurrentCell.Value = ....Text
for all of your updates.
Try using something like
VB
grdShowOfficers.CurrentRow.Cells("Last_Name").Value = txtLastName.Text
etc etc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900