Link to home
Start Free TrialLog in
Avatar of JasonWinn
JasonWinn

asked on

DataSet not updating, EndEdit not working?

Hello,
I have a textbox that is databound to my dataset. When I update text in the textbox and hit save, the information changes in the DataGridView. However, when I close the form and come back to it, the the information never made it to the DataSet.

If I click on a different cell, or do something that would automatically run an EndEdit script, then it works no problem. My Save sub, has EndEdit though, maybe but it is wrong?

Thanks

Private Void SaveButton()
{
            this.tableBindingSource.EndEdit();
            this.myDataSet.myDataSetTable.AcceptChanges();
            this.myDataSetTableAdapter.Fill(this.myDataSet.myDataSetTable);
}
Avatar of topdog770
topdog770
Flag of United States of America image

One of the simplest suggestions ( and yes something I've used ) is to set the focus to a hidden control when th save button is clicked.
Avatar of JasonWinn
JasonWinn

ASKER

I tried that but no luck.
It only works if I change the selected row/cell in the datagridview, not if I change the Focus to a regular control.

I would just have it set the focus to top row and then save it, but that wont work because sometimes they might be editing the top row, at least in theory i dont think it would work.

Call Validate();

This updates the dataset behind the datagridview
Hey Topdog,
I actually had that in my original code and it doesnt work. This is what i currently have:

            this.Validate();
            this.jobIntakeDataGridView.EndEdit();
            this.jobIntakeBindingSource.EndEdit();
            this.jobIntakeTableAdapter.Update(this.rescueScheduleDataSet.jobIntake);
ASKER CERTIFIED SOLUTION
Avatar of topdog770
topdog770
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey Topdog,
Basically I used the properties feature to bind everything, in Visual Studio.

It looks like this:

DATAGRIDVIEW PROPERTIES:
DataSource:
Viewer List Instances
      rescueScheduleData Set
DataMember: jobIntake (the table)


I know everything is probably bound correctly because if I click on a different row or cell, then click save it will save everything to the dataset/SQL. But if I just save it without changing what cell is selected then it doesnt work.

I tried this but no luck:
            this.Validate();
            this.jobIntakeDataGridView.EndEdit();
            this.jobIntakeBindingSource.EndEdit();
            this.rescueScheduleDataSet.jobIntake.GetChanges();
            this.jobIntakeTableAdapter.Update(this.rescueScheduleDataSet.jobIntake);

I think if I just added something that will change the selected row to the previous row or next row then it will work. Not sure how to do that tho:

something like:

SaveBUtton
  Try
     select NextRow
            if No Next Row
                Then
      select PreviousRow
     this.validate()
     this.datagridview.endedit
     this.bindingsource.endit()
     this.update
I tried the following but it still did not work! This changes the selected row, but its still not saving to the dataset. But If I click off of the row, then hit save it will work:

        private void saveData()
        {
           
            this.Validate();
            this.jobIntakeDataGridView.EndEdit();
            this.jobIntakeBindingSource.EndEdit();
            this.rescueScheduleDataSet.AcceptChanges();
            this.jobIntakeTableAdapter.Update(this.rescueScheduleDataSet.jobIntake);
            this.rescueScheduleDataSet.AcceptChanges();
        }

        private void viewer_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void save_Click(object sender, EventArgs e)
        {
            jobIntakeDataGridView.CurrentCell = jobIntakeDataGridView[0, jobIntakeDataGridView.Rows.Count - 2];
            saveData();
        }