Link to home
Start Free TrialLog in
Avatar of coperations07
coperations07Flag for United States of America

asked on

acceptchanges causing autoscroll

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
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of coperations07

ASKER

Yeah I tried the validating and validated events and they didn't get it done either. ..
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....
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.
SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Yeah, LINQ requires .Net 3.5 (VS2008).

Sorry for the wild goose chase
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
> 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?
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.
Did you try using the CellEndEdit event?
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.