|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
CancelCurrentEdit doesn'tUsing 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 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." 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? -- Show quoteHide quoteMany 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." > > 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 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. -- Show quoteHide quoteMany 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/default.asp?url=/library/en-us/cpguide/htm > l/cpconacceptingorrejectingchangestorows.asp > > Luke > > 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."
Operator '=' on System.DateTime and System.Double
sqltransaction System.InvalidOperationException: ExecuteReader Trying to find ClientID of web form - Update from mm/dd/yyyy to yyyy/mm/dd OleDb: Get Properties Displaying many-to-many relation data in dataGrids Trying to find ClientID of web form Cloning Datasets but also filtering DataColumn.Expression complex calculations |
|||||||||||||||||||||||