Home All Groups Group Topic Archive Search About

CancelCurrentEdit doesn't

Author
21 Jun 2005 8:38 AM
TLWood

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.
--
Many Thanks
Terry

Author
22 Jun 2005 2:30 AM
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."
Are all your drivers up to date? click for free checkup

Author
22 Jun 2005 9:13 AM
TLWood
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?


--
Many Thanks
Terry


Show quoteHide quote
"Kevin Yu [MSFT]" wrote:

> 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."
>
>
Author
24 Jun 2005 9:16 AM
[MSFT]
To cancel current edit, you may call RejectChanges() method on that datarow:

Accepting or Rejecting Changes to Rows
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconacceptingorrejectingchangestorows.asp

Luke
Author
24 Jun 2005 10:04 AM
TLWood
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.

--
Many Thanks
Terry


Show quoteHide quote
"[MSFT]" wrote:

> To cancel current edit, you may call RejectChanges() method on that datarow:
>
> Accepting or Rejecting Changes to Rows
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
> l/cpconacceptingorrejectingchangestorows.asp
>
> Luke
>
>
Author
27 Jun 2005 7:40 AM
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."

Bookmark and Share