Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug silverlight 3: datagrid is showing deleted record after submit
13 replies. Latest Post by brydo on November 3, 2009.
(0)
phang
Member
0 points
5 Posts
07-15-2009 8:43 AM |
I am using .Net RIA services, domain data source to bind the datagrid.
The data grid works well with update. However, when I add record, it is not showing in datagrid. And when I delete record, it gets deleted in grid.
However, when I call submit method of domain data source, the data grid refresh and will add the records, but the deleted records are showing back to datagrid.
Any one can help?
Jac_P
Participant
1044 points
189 Posts
07-15-2009 8:55 AM |
If your domain datasource is getting updated, then this should not be happening.
Is the record getting deleted from the database? Are you pulling data back after the updation?
Jac
07-15-2009 9:04 AM |
Below is the code behind.
dataGridClient is set to AutoLoad in xaml, and binding to ClientDataSource.
private void addNewClient_Click(object sender, System.Windows.RoutedEventArgs e) { ClientRegistrationWindow addClient = new ClientRegistrationWindow(); addClient.Closed += new EventHandler(addClient_Closed); addClient.Show(); } void addClient_Closed(object sender, EventArgs e) { ClientRegistrationWindow client = (ClientRegistrationWindow)sender; if (client.NewClient != null && client.DialogResult == true ) { CustomCollectDBContext context = clientDataSource.DomainContext as DBContext; context.Clients.Add(client.NewClient); clientDataSource.SubmitChanges(); } } private void submitButton_Click(object sender, System.Windows.RoutedEventArgs e) { DataFormClient.CommitEdit(); clientDataSource.SubmitChanges(); } private void deleteButton_Click(object sender, System.Windows.RoutedEventArgs e) { if (MessageBox.Show(ResourceMessage.DeleteConfirmation, this.Title, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { DBContextcontext = clientDataSource.DomainContext as DBContext; context.Clients.Remove((Client)dataGridClient.SelectedItem); clientDataSource.SubmitChanges(); } }
Any thing wrong with the code?
mik0
18 points
07-23-2009 5:17 AM |
I have exactly the same problem with the grid upon adding (not showing) and upon deleting (the deleted are displayed at the bottom in the grid).
I was not able to find any other solution and I ended up with the following
1. When adding some new item, I callcontext.SubmitChanges(OnSubmitCompleted, "ADD");
2. When deleting an item I simply call
context.SubmitChanges(OnSubmitCompleted, null);
Here, the source is a code behind instance of the DomainDataSource control defined in xaml and my datagrid is bound to it. The call is to provide refreshed data grid where the added items will be displayed and I do not call the load method when I’m deleting since the UI is updated (items no longer appear in the grid). In contrary, if I call the load method when I delete the item, I will end up with appearance of the deleted items at the end of the grid.
07-25-2009 12:46 AM |
thank you for making time to resolve. However, i can't really implement this.
1. I am using DomainDataSource, not the context.
2. It works temporary. Whenever the user delete records, it will temporary keep the records out from sight. But once the users add records, it loads. And ta da...the deleted records are showing back again!
I think this seems to be DomainDataSource or .NET Silverlight bug that Microsoft needs to really fix.
07-25-2009 4:35 AM |
DomainDataSource is the control that I use too, in fact my DataGrid control is bound to that DomainDataSource. In the code behind the context is derived from the DomainDataSource
in order to be able to use it for more different operations in the code behind.
The difference is probably that when I add some new record I immediately call the context.SubmitChanges method. I have not tried to postpone call to this method and to try to submit addition to a several new items at once. If I try, I will probably end up with the described duplications.
ianicbass
6 points
6 Posts
07-29-2009 7:36 PM |
I had the same problem. My solution was to make the domain data source's state to pending insert. So if I have I DDS that is tied to DataModel.myTable, the code would be something like this: DataModel.myTable newMyTable = new DataModel.myTable(); myContext context = dds.DomainContext as myContext; context.myTable.Add(newMyTable); Then if you are using DataForm to enter info, just set DataForm.CurrentItem = newMyTable and then on the save event just add dds.SubmitChanges(). This will refresh any controls tied to the dds. Also do not forget to issue dds.RejectChanges() if user cancels. Hope this helps. Let me know if you guys need more info.
fchopo
3 Posts
07-30-2009 5:45 AM |
Hello Everybody,
I'm facing the same problem and I've been trying to solve it for two days, but couldn't find any solution. I do not understand your solution... Could you please show more details (in which events should I place the code?).
I have a DDS which is tied to a DomainContext (xaml file):
1 <riaControls:DomainDataSource x:Name="dsTipoSiniestros" LoadSize="20" QueryName="GetSituacion_SiniestroQuery" AutoLoad="True" SubmittedChanges="dsTipoSiniestros_SubmittedChanges"> 2 <riaControls:DomainDataSource.DomainContext> 3 <ds:AMBContext/> 4 </riaControls:DomainDataSource.DomainContext> 5 </riaControls:DomainDataSource>
Then I have a datagrid showing main data, and a dataform showing details data, both tied to the DomainDataSource. I have a "save" button, which calls the submitchanges method.
1 Private Sub btnGuardarCambios_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) 2 If Not dsTipoSiniestros.IsSubmittingChanges Then 3 dsTipoSiniestros.SubmitChanges() 4 End If 5 End Sub
Everything is ok, except that the datagrid shows deleted records. Could you help me, please?
Thank you very much in advance.
07-30-2009 12:16 PM |
fchopo, Here's the code for deleting a record (Just convert it to VB): AMBContext c = dsTipoSiniestros.DomainContext as AMBContext; c.Situacion_Siniestro.Remove(datagrid.SelectedItem as Situacion_Siniestro); c.SubmitChanges(); Just change datagrid with your datagrid's name and this should refresh automatically. Hope this helps. Let me know if you have other questions.
07-30-2009 1:09 PM |
I found the solution for my code. I hope this is helping you.
What i did i to add this following code after my delete. Below is my code:
clientDataSource.SubmitChanges();
context.Load(context.GetClientQuery(),
clientDataSource.Load();
07-31-2009 4:09 AM |
Thanks IanicBass and Phang,
But none of the solutions worked. I'm still facing the same problem. The records are deleted from the database, but they are showed on the datagrid.
I'm placing the code you showed in the dataform_deletingitem event. Is that right? I have tested many things, but I have find no solution at all.
Do you send your changes inmediately (after inserting, editing or deleting one record), or do you have a submit button that sends all the changes made to the data?
Thank you for your help!!!
07-31-2009 7:36 AM |
Hello Again,
Finally I have found a solution. I'm just invoking submitchanges everytime there's a change in some of the data in the dataform (instead of waiting the user to click a submit button). In the dataform_editended I'm placing this piece of code:
1 Private Sub dfTipoSiniestro_EditEnded(ByVal sender As Object, ByVal e As System.Windows.Controls.DataFormEditEndedEventArgs) Handles dfTipoSiniestro.EditEnded2 If e.EditAction = DataFormEditAction.Commit Then3 dsTipoSiniestros.SubmitChanges()4 dsTipoSiniestros.Load()5 End If6 End Sub
But in this way, I still have problems with the delete record operation. Moreover, It doesn't exist any event like dataform_deletedItem. Reading in some other posts I found a solution, which is showed next:
1 Private Sub dfTipoSiniestro_DeletingItem(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles dfTipoSiniestro.DeletingItem 2 Dispatcher.BeginInvoke(AddressOf DeleteFunction) 3 End Sub 4 5 Private Sub DeleteFunction() 6 If Not dsTipoSiniestros.DomainContext.IsSubmitting Then 7 dsTipoSiniestros.SubmitChanges() 8 dsTipoSiniestros.Load() 9 End If 10 End Sub
I created a delegate function, which is invoked when the DeletingItem is invoked.
In this way everything is ready and working properly.
Hope that this is helpful for some other people.
Thank you very much for your help!
08-01-2009 1:46 AM |
Thank you for all your reply!
It seems we have multiple solutions with our problems. Hope this help others with our various solutions.
brydo
4 points
2 Posts
11-03-2009 4:12 PM |
Same problem... deleting a record and calling SubmitChanges() removed the record from the database but not from the DataGrid.
I found that calling SubmitChanges() from the DomainDataSource control resulted in this "phantom record" remaining in my DataGrid, but calling SubmitChanges() directly from the DomainContext did not.
When adding or deleting a record, I also needed to call SubmitChanges() directly from the DomainContext object in order to keep my DataGrid in sync. In these cases, I needed to use the overload of SubmitChanges() which takes a callback function. The callback function was responsible for calling the Load() method of the DomainDataSource object. However, using this same callback function for deletes (in turn calling the Load() method) resulted in the original behavior of the stubborn record in the grid.
It's probably not the "correct" way of doing things, but it's the only pattern that I could find that works.