annoying! (DataRowState.Modified)

Hi All,

I have various controls on a tab page. After i run the fill from the dataadapter i get (DataRowState.Modified = true) fair enough i thought, perhaps somthing minor is getting changed during the databind. So i update the dataset and get (DataRowState.Modified = false).  Thats good you would imagine the dataset is sitting pretty ready to detect any real changes made by the user.

However it seems that when i change tabs (via tab validate event) even without making a manual change to the dataset (via bound controls), the  (DataRowState.Modified) ends up being true and hence the user is prompted to save changes.

Something anomolous is changing the rowstate!

Ideas?

Regards

DiDGE
LVL 2
djdidgeAsked:
Who is Participating?
 
ptakjaCommented:
So you fill each time the user switches to TabMain?  The fill is what is causing the modified bit to get set.  When you fill a dataset you are changing every row in the table(s), thus the Modified flag being set.

One thing you could try is create a boolean flag that you set when the user hits the Search tab.  Then when you move them to the Main tab you check that flag.  If set, you know they came from the search tab and you fill the dataset.  Then accept the changes and clear the flag.  Now the next time they come to the main tab check the flag again.  If it is not set, don't fill the dataset, use the existing data.  If the user hits the search tab again and does a search, reset the search boolean and repeat the process.

Would that solve the problem?
0
 
ptakjaCommented:
When you change tab pages are you rebinding your dataset?  That would cause the Modified bit to get set.
0
 
djdidgeAuthor Commented:
im unbinding and rebinding a lot unfortunately as i couldnt seem to get a consistent binding context working.

However, as a test i added a command button that updated the dataset and msgboxed DataRowState.Modified... So as a test i click the update button just before i change the tab... this should save any and all changes and it return modified as false (which it does). And yet when i click the tab straight after modified = true and i get it asking to update again :o/
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ptakjaCommented:
Gotcha.  But, when the tab page is changed, do you rebind the dataset?  In other words, do you rebind in the tabpage changed event handler?
0
 
djdidgeAuthor Commented:
Having added breakpoints to check that the unbind/rebind isnt running without me knowing i can confirm that it happens elsewhere, and so doesnt seem to be what is causing this :o/
0
 
ptakjaCommented:
One thing you could try is after you bind the dataset, call the AcceptChanges method which will clear that flag.  See if that works.
0
 
djdidgeAuthor Commented:
ok...

I did this         MsgBox(dsProd.HasChanges(DataRowState.Modified))   just after the binds and it returned False .... this means that binding isnt the issue

I did this         MsgBox(dsProd.HasChanges(DataRowState.Modified))   it returned false
                     Me.tabAll.SelectedTab = tabMain
                     MsgBox(dsProd.HasChanges(DataRowState.Modified))   it returned true

so it looks like the 'selectedTab = ' bit changes the rowstate

on the first 'selectedTab = '  i can use the AcceptChanges bit as no data has been changed (this is the case as we have just come from a 'search' tab to the edit tab (tabmain)), this saves me doing an update atleast. But as for a true validation of changes when i change tab im at a loss.

I have to be honest tab pages are almost more hasle than they are worth!

0
 
ptakjaCommented:
Wait a sec.  I asked the wrong question. DUH! :-|  When you change tab pages are you re-filling the dataset?  Can you post some code so we can see what is going on?
0
 
djdidgeAuthor Commented:
there are about 7 tabs... the first is a search page. Selections made from there take the user to tabmain. The fill happens here.

I would be happy to post code but tbh i'm really not sure which part might be relevant as the project is fairly big.

If i could store the rowstate in a seperate boolean i could evaluate that instead. The only problem with that would be finding a suitable event to use to update the boolean. Ideally it would be on an event attached to the click of the tab header, but i cant seem to find one that will fire at a suitable time (before the rowstate is changed by the annoying tabpage!)
0
 
djdidgeAuthor Commented:
perhaps i could put a line object (or .net equiv) along the bottom of the tab heads and use the mouse over event.... a bit dirty, but novell i guess.



0
 
ptakjaCommented:
Incidentally, there is no .Net equivalent of the VB6 line object.  You would have to draw the line yourself using GDI+ and maintain it's state etc...not pretty.

If you wanted to try that route, you could put a label control on the tab header and use it instead of the Text property for the tab page.  Not sure if that would work good or not, but it may be worth a try if what I suggested above doesn't cut the mustard.
0
 
djdidgeAuthor Commented:
i can see how that might work with some designs, however my prog works a little differently. But its almost what i described above.

However i think i have made a breakthrough! i tried validating the rowstate right at the beginning of the tabMain_Validating sub... it was False! hence i can use that true condition to decide weather to update or not.

unfortunately my time has run out for today. I must leave for home now. But i will check this first thing in the morning and then hopefully close the question.

Thanks for your help today.

Speak to you tomorrow.

Regards

DiDGE
0
 
RonaldBiemansCommented:
There is an option you can set when filling from the dataadapter,
yourdataadapter.AccectChangesDuringFill = False

this way when you fill your dataadapter all records are unchanged
0
 
djdidgeAuthor Commented:
it seems to be not related to the tabpage click....

with the rowstate set as FALSE (after fill)...

without making any manual changes to the bound controls i run this code...

fMain.BindingContext(dsProd, "ProdRec").EndCurrentEdit()
MsgBox(dsProd.HasChanges(DataRowState.Modified))

and it returns TRUE! what is going on here! It should be FALSE because ive not made any changes! Am i misunderstanding how thsi whole thing works?!

Regards

DiDGE
0
 
djdidgeAuthor Commented:
do i need to use a BindingManagerBase ?
0
 
dsevansCommented:
Hi ,

I have a similar problem but will post a new question to raise the profile of the topic.

DSE
0
 
djdidgeAuthor Commented:
Having opened a similar thread on http://www.visualbasicforum.com/showthread.php?t=182796 it seems that calling EndCurrentEdit will always set  the rowstate.modifed = true

for my purposes a true value of rowstate.modifed can be gained by editing a text box and then changing focus to another bound control.

Ill leave the question open for a few days to facilitate further discussion then i will close.

Regards

DiDGE
0
 
djdidgeAuthor Commented:
...it looks like i dont have to change focus afterall
0
 
djdidgeAuthor Commented:
my thread Date: 08/11/2004 01:49PM BST was eventually the resolution i was looking for but to give credit for helping me work towards the solution im awarding the points to both contributors.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.