469,358 Members | 1,518 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

HasChanges() returns incorrect value

I have a DataSet that contains all my data. From this DataSet, let's call it DS, I have 2 views that are based off of 2 seperate tables. We'll call them DataView History and DataView Info. I have a grid on my winForm that is dataBound to the Info view along with 2 combo boxes and 1 datetime picker. Everything works fine with these controls so that the filtering is done automatically by the grid. The other DataView, is bound to textboxes on another tab in my winForm. When I type information into these textboxes, change focus or leave focus, and try to click a button to that calls a save function that calls BindingContext[].EndCurrentEdit() for a tables in the DS. Then immediately after I check the DS to see if it has any changes by calling DS.HasChanges()... this function always returns false. If I debug my program, and pause it right at the HasChanges() step, i can check the following: DS.Tables["Info"].Rows[0]["address"] and I get the value that I entered into the textbox.

Why does the DS think that there is no changes to itself when I can clearly see that there is something there that wasn't before?

If I didn't give enough info, let me know... I'm still alittle new to this stuff
Jun 20 '07 #1
8 1883
nateraaaa
663 Expert 512MB
I have a DataSet that contains all my data. From this DataSet, let's call it DS, I have 2 views that are based off of 2 seperate tables. We'll call them DataView History and DataView Info. I have a grid on my winForm that is dataBound to the Info view along with 2 combo boxes and 1 datetime picker. Everything works fine with these controls so that the filtering is done automatically by the grid. The other DataView, is bound to textboxes on another tab in my winForm. When I type information into these textboxes, change focus or leave focus, and try to click a button to that calls a save function that calls BindingContext[].EndCurrentEdit() for a tables in the DS. Then immediately after I check the DS to see if it has any changes by calling DS.HasChanges()... this function always returns false. If I debug my program, and pause it right at the HasChanges() step, i can check the following: DS.Tables["Info"].Rows[0]["address"] and I get the value that I entered into the textbox.

Why does the DS think that there is no changes to itself when I can clearly see that there is something there that wasn't before?

If I didn't give enough info, let me know... I'm still alittle new to this stuff
Please look at this example.

Nathan
Jun 20 '07 #2
I looked at that example and called DS.GetChanges() and DS.GetChanges(DataRowState.Modified) and both returned null. I've also tried the following:

foreach(DataRow r in DS.Tables["Info"].Rows)
{
if(r["address"].RowState == DataRowState.Modified)
{
//debug here, even though it never gets here
}
}

so there seems to be no rows (atleast to the DS) that have had any changes...

thanks for the fast response!
Jun 20 '07 #3
nateraaaa
663 Expert 512MB
I looked at that example and called DS.GetChanges() and DS.GetChanges(DataRowState.Modified) and both returned null. I've also tried the following:

foreach(DataRow r in DS.Tables["Info"].Rows)
{
if(r["address"].RowState == DataRowState.Modified)
{
//debug here, even though it never gets here
}
}

so there seems to be no rows (atleast to the DS) that have had any changes...

thanks for the fast response!
I also found this example. Let us know if trying the code in this example works for you.

Nathan
Jun 20 '07 #4
yeah, i've run along this code out there and I'm nearly doing the same thing... I'm binding my textboxes with the following:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1");

and I've also tried:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;

and also:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

still no luck...I've tried now to debug the program when the TextChanged event is raised of my textbox. When I type something new in the text box (1 letter at a time) and debug the program and look at the DS.Tables["Info"].Rows[1]["address"] which has the original value, the rowstate for this row which is Unchanged, and the Text value of my textbox which as the new letter i typed. I just through in Row[1] because it just happens to be the row, for ease of debug use. But here's what I don't understand... when i click off of the textbox and back onto it again and type 1 more character, i enter into debug mode again. But this time, the DS contains the changes that the textbox had when it lost focus, ok, but the RowState is still Unchanged.... shouldn't the RowState have been updated since the data inside the row had been changed?
Jun 20 '07 #5
nateraaaa
663 Expert 512MB
yeah, i've run along this code out there and I'm nearly doing the same thing... I'm binding my textboxes with the following:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1");

and I've also tried:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;

still no luck...I've tried now to debug the program when the TextChanged event is raised of my textbox. When I type something new in the text box (1 letter at a time) and debug the program and look at the DS.Tables["Info"].Rows[1]["address"] which has the original value, the rowstate for this row which is Unchanged, and the Text value of my textbox which as the new letter i typed. I just through in Row[1] because it just happens to be the row, for ease of debug use. But here's what I don't understand... when i click off of the textbox and back onto it again and type 1 more character, i enter into debug mode again. But this time, the DS contains the changes that the textbox had when it lost focus, ok, but the RowState is still Unchanged.... shouldn't the RowState have been updated since the data inside the row had been changed?
Are you calling the AcceptChanges method?
Jun 20 '07 #6
no, the AcceptChanges() will be called after the DS has been sent to the database and comes back
Jun 20 '07 #7
Well, I found a method that works, but I'm not sure how clean it is. On my databinding area, i set my text boxes to all be bound like the following:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

I added the ".DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;" so that the user wouldn't have to click out of the textbox before clicking save.

But what I did in my save method is that I had to run through all all the rows in the view that I had created:

for (int i = 0; i < _dependentsContactView.Count; i++)
_dependentsContactView[i].EndEdit();

This modified the RowState of the correct rows to me "Modified" instead of "Unchanged". After this, I'm still running through all of my DS tables and calling EndCurrentEdit() on them. After that I'm checking to see if DS.HasChanges() is true (thank goodness it finally is, YEAH!!!) then I'm saving.

I was originally thinking that if I'm calling EndCurrentEdit() on the DS then that should work, but I have to EndEdit() first on the view based off of that table!

Thanks for all the help, I really appreciate it
Jun 20 '07 #8
nateraaaa
663 Expert 512MB
Well, I found a method that works, but I'm not sure how clean it is. On my databinding area, i set my text boxes to all be bound like the following:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

I added the ".DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;" so that the user wouldn't have to click out of the textbox before clicking save.

But what I did in my save method is that I had to run through all all the rows in the view that I had created:

for (int i = 0; i < _dependentsContactView.Count; i++)
_dependentsContactView[i].EndEdit();

This modified the RowState of the correct rows to me "Modified" instead of "Unchanged". After this, I'm still running through all of my DS tables and calling EndCurrentEdit() on them. After that I'm checking to see if DS.HasChanges() is true (thank goodness it finally is, YEAH!!!) then I'm saving.

I was originally thinking that if I'm calling EndCurrentEdit() on the DS then that should work, but I have to EndEdit() first on the view based off of that table!

Thanks for all the help, I really appreciate it
Great. I am glad you were able to find a solution. Thank you for sharing.

Nathan
Jun 20 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Michiel | last post: by
3 posts views Thread by Stephan | last post: by
12 posts views Thread by chellappa | last post: by
2 posts views Thread by nikolacace | last post: by
1 post views Thread by `Zidane Tribal | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.