Datagrids (again)

  • Thread starter Thread starter mfleet1973
  • Start date Start date
M

mfleet1973

Hi.

A scenario has come up in which I'm not sure how to handle. What is
happening is the user enters information in a cell of the grid. If the
user then quits the application as soon as he finishes entering the
data, the data entered in the cell is not saved. I have the following
code in the closing event of the form:

If DataSet.HasChanges Then
Try
DataAdapter.Update(DataSet.GetChanges, "Table")
DataSet.AcceptChanges()
Catch e As Exception
MsgBox(e.message)
Exit Sub
End Try
End If

However, if the user tabs to the next cell, the data is saved. Is
there something that can be done to save the data without having to
tell the users that they must tab from the cell upon entering data? I
tried replicating a tab key press (SendKeys.Send("{Tab}")) before
updating but this did not fix it.

Thanks a lot for the past and future help!

Mike.
 
Mike,

I have given you an aswer on this standard question some days ago in this
newsgroup.

Cor
 
Hi Cor.

Actually the last datagrid post I did was concerning visual controls
that were not in the grid but were pointing to the same record. The
solution was to call EndCurrentEdit of the currencymanager which fixed
the problem.

This issue involves changes that are done within a cell in a grid.
User enters data in the cell, never tabbing to the next cell, and then
quits the app which triggers saving to the db. The changes are not
saved. I tried calling EndCurrentEdit but that did not fix the
problem.

Thanks!
 
so,

if i understand correctly, the user makes changes in a cell ... than exits
the application - presses the close button on the window control bar ... the
data is not changed in the dataadapter because the cell did not lose focus
and the change is not ackonwledged ...

in the closing event, get the current cell with focus and set the focus to
the next cell ... force a tab or something ... or set focus to another
control on the window ... anything to move the cursor / focus out of the
curent cell ... this should force the data change to be acknowledge and the
EndCurrentEdit should work...and thus the update to save the data ...
 
On validating of the grid control throw a boolean variable "IsDirty"
and on closing of the form:

If IsDirty then
If MsgBox("You have unsaved changes. Would you like to save your
changes now?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then e.Cancel =
True
End If
 
Mike,

Simple,

Don't start with this, a datagrid has in front a little pencil to
acknowledge the editing, so let the user do that. You are now building an
application that is not working confirm the standards of that control.

Just my thought,

Cor
 
Have you stepped through to see if the .HasChanges is returning as true?
I'm guessing here, but maybe the change to the cell in the datagrid isn't
making the change to the DataSet until after the cell loses focus.

Also I don't think the .AcceptChanges is necessary as calling the
DataAdapter.Update should set all rowstates to unchanged.
 
Back
Top