We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

acceptchanges causing autoscroll

coperations07
on
Medium Priority
357 Views
Last Modified: 2012-05-11
Hi,
I have a datagridview and I want to calculate the total for one of the columns when a cell value is changed. The only way I've found to do this so far is to call acceptchanges for the datatable. However, acceptchanges makes the datagridview scroll away from the value that was just entered.

The total will calculate without calling acceptchanges, but it does not include the currently changed cell value. I haven't found an event to use where the cell value updates without calling acceptchanges.

What can I try here?

Thx,
Dave
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
You can try using the Cell_Validating event but the trouble is that the new value is only committed to the datatable when the cell loses focus.

http://windowsclient.net/learn/video.aspx?v=13416

Author

Commented:
Yeah I tried the validating and validated events and they didn't get it done either. ..

Commented:
Let's be clear about something.... Many people completely misunderstand what AcceptChanges does.  It may not be doing what you expect it do.  This is because th name is somewhat misleading...  instead of "saving the current changes", it actually does the exact opposite!  AcceptChanges will *remove* all of the internal markers where changes have been made.  This makes it "look like" there are no changes that need to be saved (even though changes were actually made).

The DataAdapter uses this field to determine what should be done when updating the DataTable back to the underlying database.  So, AcceptChanges will "erase all knowledge of any changes", and therfore the DataAdapter will not send any changes to the backend database (since it didn't detect any).

... sorry for the interruption, we now return you to your original question....

Author

Commented:
Thanks graye.  AcceptChanges isn't necessarily something that I want to use.  It's just the only thing I've come across that gets close to the results I am looking for.  I can use the update method of the datagridview to display the value before the code finishes executing, but that doesn't help me when it comes to a calculation with the datatable.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
LINQ seems interesting, but I haven't been able to get it to work for me yet?  I am using VS2005. AsEnumerable() isn't recognized by intellisense after datatable.
do I have to import something?
This is where I'm at:

            Dim myLINQ = (from row in tSorter.AsEnumerable() _
                            Where Selected_CF > 0
                            Select row.Min_Cht).sum()

thanks,
Dave

Commented:
Yeah, LINQ requires .Net 3.5 (VS2008).

Sorry for the wild goose chase
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks CodeCruiser,

The prob I'm running into now happens when a row is edited after the initial entry.  When this happens the Compute will include the edited row, but then I am adding it again.  How can I handle this?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
> dMinCht = dMinCht + Me.dgResults.CurrentRow.Cells("Min_Cht").Value
Why not remove the above line then? Is it required when adding a new line? Or do you mean that the old value is included in the compute and you want to use the new value?

Author

Commented:
When an entry is made to the dgv it doesn't get included in the Sum when I use the Compute function, so I get the value of the current cell from the dgv and add it in.  If it is edited again then the Sum will pick up the previous entry.  I'm using the cellchanged event and the datatable doesn't seems to update until after the event finishes.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Did you try using the CellEndEdit event?

Author

Commented:
Thanks for the help guys.  The CellEndEdit didn't work for me either, but I used an IF..Else to get what I needed.  Thanks for the LIINQ suggestion Graye, I will check it out when I upgrade.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.