Solved

annoying! (DataRowState.Modified)

Posted on 2004-08-10
19
688 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:djdidge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
19 Comments
 
LVL 14

Expert Comment

by:ptakja
ID: 11762503
When you change tab pages are you rebinding your dataset?  That would cause the Modified bit to get set.
0
 
LVL 2

Author Comment

by:djdidge
ID: 11762697
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
 
LVL 14

Expert Comment

by:ptakja
ID: 11762729
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 2

Author Comment

by:djdidge
ID: 11762945
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
 
LVL 14

Expert Comment

by:ptakja
ID: 11762972
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
 
LVL 2

Author Comment

by:djdidge
ID: 11763250
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
 
LVL 14

Expert Comment

by:ptakja
ID: 11763371
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
 
LVL 2

Author Comment

by:djdidge
ID: 11763477
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
 
LVL 2

Author Comment

by:djdidge
ID: 11763517
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
 
LVL 14

Accepted Solution

by:
ptakja earned 200 total points
ID: 11763554
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
 
LVL 14

Expert Comment

by:ptakja
ID: 11763573
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
 
LVL 2

Author Comment

by:djdidge
ID: 11763611
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
 
LVL 25

Assisted Solution

by:RonaldBiemans
RonaldBiemans earned 50 total points
ID: 11763965
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
 
LVL 2

Author Comment

by:djdidge
ID: 11770653
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
 
LVL 2

Author Comment

by:djdidge
ID: 11770884
do i need to use a BindingManagerBase ?
0
 

Expert Comment

by:dsevans
ID: 11771793
Hi ,

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

DSE
0
 
LVL 2

Author Comment

by:djdidge
ID: 11772172
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
 
LVL 2

Author Comment

by:djdidge
ID: 11773363
...it looks like i dont have to change focus afterall
0
 
LVL 2

Author Comment

by:djdidge
ID: 11808558
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

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question