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);
}
C#

Avatar of undefined
Last Comment
JasonWinn

8/22/2022 - Mon
topdog770

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.
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.

topdog770

Call Validate();

This updates the dataset behind the datagridview
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
JasonWinn

ASKER
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
topdog770

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
JasonWinn

ASKER
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);

JasonWinn

ASKER
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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
JasonWinn

ASKER
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();
        }