PC Review


Reply
Thread Tools Rate Thread

CancelCurrentEdit doesn't

 
 
=?Utf-8?B?VExXb29k?=
Guest
Posts: n/a
 
      21st Jun 2005
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
 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      22nd Jun 2005
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."

 
Reply With Quote
 
=?Utf-8?B?VExXb29k?=
Guest
Posts: n/a
 
      22nd Jun 2005
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


"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."
>
>

 
Reply With Quote
 
[MSFT]
Guest
Posts: n/a
 
      24th Jun 2005
To cancel current edit, you may call RejectChanges() method on that datarow:

Accepting or Rejecting Changes to Rows
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconacceptingorrejectingchangestorows.asp

Luke

 
Reply With Quote
 
=?Utf-8?B?VExXb29k?=
Guest
Posts: n/a
 
      24th Jun 2005
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


"[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/de...us/cpguide/htm
> l/cpconacceptingorrejectingchangestorows.asp
>
> Luke
>
>

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      27th Jun 2005
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."

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro doesn't properly record AutoSum (and SendKeys doesn't work) =?Utf-8?B?Y3JpbXNvbmtuZw==?= Microsoft Excel Programming 2 21st Nov 2006 02:11 PM
CancelCurrentEdit in DataGrid Microsoft ADO .NET 8 20th Oct 2005 09:51 AM
Binding property with CancelCurrentEdit Marina Microsoft Dot NET Framework Forms 11 6th Apr 2005 07:37 PM
Binding property with CancelCurrentEdit Marina Microsoft Dot NET 11 6th Apr 2005 07:37 PM
BindingManagerBase.CancelCurrentEdit() problem johnb41 Microsoft VB .NET 0 3rd Mar 2005 05:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:46 AM.