CancelCurrentEdit doesn't

G

Guest

Hi

Using Windows.Forms in ADO.NET in VB.NET 2003.

I have 3 dataviews of the same datatable in a dataset, each a subset of the
datatable by means of rowfilter. for example:

Me.dv1 = New DataView(myDataTable)
Me.cm1 = Me.BindingContext(Me.dv1)
Me.dv1.RowFilter = "Actions LIKE '%(1)%' AND Condition = 1"

Me.dv2 = New DataView(myDataTable)
Me.cm2 = Me.BindingContext(Me.dv2)
Me.dv2.RowFilter = "Actions LIKE '%(3)%' AND Condition = 1"

Each dataview is bound to it's own datagrid.

Editing data within the datagrids updates the current version of the row and
not the proposed version, and hence the CancelCurrentEdit on the
CurrencyManagers does not work.

Any help would be much appreciated.
 
K

Kevin Yu [MSFT]

Hi Terry,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you bind 3 DataViews from the same
DataTable to DataGrids, the changed data is not synchronized, and the
CancelCurrentEdit doesn't work. If there is any misunderstanding, please
feel free to let me know.

I checked your code, but didn't find anything wrong. I wrote a similar
project on my machine and it works fine for me. Would you try the following
code which connects to the Employee table in Northwind database.

Private cm1 As CurrencyManager
Private cm2 As CurrencyManager

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Me.SqlDataAdapter1.Fill(ds)

Dim dv1 As New DataView(ds.Tables(0))
dv1.RowFilter = "Title='Sales Representative'"
Dim dv2 As New DataView(ds.Tables(0))
dv2.RowFilter = "TitleOfCourtesy='Mr.'"

Me.DataGrid1.DataSource = dv1
Me.DataGrid2.DataSource = dv2

Me.cm1 = CType(Me.BindingContext(dv1), CurrencyManager)
Me.cm2 = CType(Me.BindingContext(dv2), CurrencyManager)
End Sub

Private Sub DataGrid1_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles DataGrid1.KeyUp
If e.KeyCode = Keys.Escape Then
Me.cm1.CancelCurrentEdit()
End If
End Sub

You can try to modify your app according to this code snippet. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Thanks Kevin

I see the problem now. Changing rows in the datagrid calls an endedit on the
current row.

I have a Save and Cancel button on the form containing the datagrids. I am
working in a completely disconnected dataset so acceptchanges etc. are of no
use.

There is no table wide canceledit or endedit so I guess the only way to save
or cancel all the changes made to a bound datagrid is to make a copy of the
table and restore in on cancel. Is this the recommended method?
 
G

Guest

Yes, this will set the data back to the original values, i.e. those that were
originally retreived from the database, not to the current data in the
dataset which may well have since been modified.
 
K

Kevin Yu [MSFT]

Hi Terry,

If you're working with a completely disconnected DataSet, I suggest you
call AcceptChanges during Save operation and call RejectChanges during
Cancel operation. So when Cancel button is clicked, all the changes the
user made after the the last AcceptChanges call will be rolled back. the
AcceptChanges and RejectChanges are actually modifying the RowState of the
DataRow. It makes no difference whether the data in the DataSet is created
by your program or get from database.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top