I have a grid bound to an ObservableCollection and the following code is used to add a new record to the collection then select the new record in the grid;
This works perfectly unless the user has grouped the records. When the records are grouped the new record is not added to the grid and the code to locate the record in the grid doesn't locate the new record.
I have also confirmed the grid DataLoaded event doesn't fire if the records are grouped but does fire otherwise. There are no filters applied to the grid.
What do I have to do to force the grid to load and display the record?
'Add the new object to the collection...mcolStudents.Add(moStudent)'Locate the record in the grid...With gvStudents For Each item As StudentView In .Items If item.StudentId = moStudent.StudentId Then .SelectedItem = item .ScrollIntoView(item) Exit For End If NextEnd WithThis works perfectly unless the user has grouped the records. When the records are grouped the new record is not added to the grid and the code to locate the record in the grid doesn't locate the new record.
I have also confirmed the grid DataLoaded event doesn't fire if the records are grouped but does fire otherwise. There are no filters applied to the grid.
What do I have to do to force the grid to load and display the record?
6 Answers, 1 is accepted
0
Hi,
As I understand you observe the problem only when RadGridView is grouped. May I ask you to configure your RadGridView setting GroupRenderMode="Flat"?
Then, you say DataLoaded event doesn't fire. The DataLoaded event will be raised every time when a CollectionChanged notification is raised for RadGridView.Items collection. Such a notification will be raised every time a data operation like sorting, grouping or filtering is performed. The operation can be performed from the UI or in code.
So, this event should be raised every time you perform grouping.
May I ask you to confirm the version you are using?
Regards,
Didie
Telerik
As I understand you observe the problem only when RadGridView is grouped. May I ask you to configure your RadGridView setting GroupRenderMode="Flat"?
Then, you say DataLoaded event doesn't fire. The DataLoaded event will be raised every time when a CollectionChanged notification is raised for RadGridView.Items collection. Such a notification will be raised every time a data operation like sorting, grouping or filtering is performed. The operation can be performed from the UI or in code.
So, this event should be raised every time you perform grouping.
May I ask you to confirm the version you are using?
Regards,
Didie
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Raymond
Top achievements
Rank 1
answered on 30 Apr 2014, 09:06 PM
Hi Didie,
I set GroupRenderMode to Flat as requested but this made no difference.
I placed a breakpoint in the code for the DataLoaded event and it does fire when;
- the collection is first added to the DataContext of the grid
- the grouping of the grid is changed
- an object is added to the collection AND the grid is NOT grouped
However the DataLoaded event does not fire if the grid is grouped and an object is added to the collection.
Following is a simplified example of the code I am using;
01.Private Sub gvFooBars_DataLoaded(sender As Object, e As EventArgs) Handles gvFooBars.DataLoaded02. With gvFooBars03. If (.Items.ItemCount > 0) And (moFooBar Is Nothing) Then .SelectedItem = .Items(0)04. End With05.End Sub06. 07.Private Sub LoadRecords(ByVal ScenarioId As Integer)08. 'Load the FooBar records...09. mcolFooBars = New ObservableCollection(Of FooBar)(gcolFooBars.Where(Function(f) f.ScenarioId = ScenarioId).OrderBy(Function(f) f.TemplateName).ThenBy(Function(f) f.FooBarType))10. gvFooBars.DataContext = mcolFooBars11. 12. 'If there are no existing records create a new object...13. If (mcolFooBars.Count = 0) Then moFooBar = New FooBar14.End Sub15. 16.Public Function Save() As Boolean17. Dim bSaved As Boolean = False18. Dim bNew As Boolean = False19. 20. Const PROC As String = "Save FooBar Record"21. 22. If moFooBar.IsDirty Then23. bNew = moFooBar.IsNewRecord24. bSaved = FooBarBusiness.Save(moFooBar) 25. 26. if bSaved Then27. 'If this was a new record then add it to the FooBar list...28. If bNew Then29. 'Add the new object to the collections...30. mcolFooBars.Add(moFooBar)31. gcolFooBars.Add(moFooBar)32. 33. 'If the records are grouped then it appears the record is not added to the grid when it 34. 'is added to the mcolFooBars collection?35. If gvFooBars.IsGrouping Then36. Dim iFooBarId As Integer = moFooBar.FooBarId37. Call LoadRecords(miScenarioId)38. moFooBar = FooBarBusiness.GetRecord(iFooBarId)39. End If40. 41. 'Select the object in the grid...42. With gvFooBars43. For Each item As FooBarView In .Items44. If item.FooBarId = moFooBar.FooBarId Then45. .SelectedItem = item46. .ScrollIntoView(item)47. Exit For48. End If49. Next50. End With51. Else52. .53. .54. .55. End If56. 57. gvFooBars.CalculateAggregates()58. End If59. End If60. 61. Return bSaved62.End FunctionLine 30 will trigger the DataLoaded event if the grid is not grouped.
Please note the breakpoint is on line 2 not line 3 so my problem is not that line 3 doesn't execute it is that execution does not get to line 2.
I am currently using version 2014.1.224.40.
Regards,
Ray
0
Hi Ray,
I am still not able to reproduce any issue at my side. I have attached my test project as a reference.
Would you please check it and modify it so that the issue to be observed?
In order to test it you should:
1. Run it
2. Group by any column
3. Click the button
5. Observe the value of the infoLabel, next to the button.
Let me know about the result.
Regards,
Didie
Telerik
I am still not able to reproduce any issue at my side. I have attached my test project as a reference.
Would you please check it and modify it so that the issue to be observed?
In order to test it you should:
1. Run it
2. Group by any column
3. Click the button
5. Observe the value of the infoLabel, next to the button.
Let me know about the result.
Regards,
Didie
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Hi,
You can find the test solution attached.
Regards,
Didie
Telerik
You can find the test solution attached.
Regards,
Didie
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Raymond
Top achievements
Rank 1
answered on 02 May 2014, 12:29 AM
Hi Didie,
Thanks for your reply. I tried the example program you provided and it worked without any problems however I still haven't been able to get my code to work.
I modified the code as follows to provide some feedback on the problem;
The attached screens show the results of my testing as follows;
The entries for 10:08:34 show the statements executed from Screen 2 when the 1st object was added.
The entry for 10:10:23 is when the grouping was applied.
The entry for 10:10:38 is when the 2 object was added (but wasn't displayed in the grid).
The entry for 10:11:46 is when the grouping was removed and the record was then displayed. Any help you can provide on this would be greatly appreciated.
Regards,
Ray
Thanks for your reply. I tried the example program you provided and it worked without any problems however I still haven't been able to get my code to work.
I modified the code as follows to provide some feedback on the problem;
Private Sub gvFooBars_DataLoaded(sender As Object, e As EventArgs) Handles gvFooBars.DataLoaded With gvFooBars Debug.Print(String.Format("{0} - gvFooBars_DataLoaded", Date.Now.ToString("hh:mm:ss"))) If (.Items.ItemCount > 0) And (moFooBar Is Nothing) Then .SelectedItem = .Items(0) End WithEnd SubPublic Function Save() As Boolean
.
.
.
If bNew Then '-- Add the new object to the collections ----------------------------------------------- Debug.Print(String.Format("{0} - Adding object to collection", Date.Now.ToString("hh:mm:ss"))) mcolFooBars.Add(moFooBar) gcolFooBars.Add(moFooBar) ''-- If the records are grouped then it appears the record is not added to the grid when it ''-- is added to the mcolFooBars collection? 'If gvFooBars.IsGrouping Then ' Dim iFooBarId As Integer = moFooBar.FooBarId ' Call LoadRecords(miScenarioId) ' moFooBar = FooBarBusiness.GetRecord(iFooBarId, True) 'End If '-- Select the object in the grid ------------------------------------------------------- Dim item = mcolFooBars.Where(Function(f) f.FooBarId = moFooBar.FooBarId).FirstOrDefault If (item IsNot Nothing) Then Debug.Print(String.Format("{0} - Object located in collection subset", Date.Now.ToString("hh:mm:ss"))) With gvFooBars For Each item As FooBarView In .Items If item.FooBarId = moFooBar.FooBarId Then Debug.Print(String.Format("{0} - Object located in GridView", Date.Now.ToString("hh:mm:ss"))) .SelectedItem = item .ScrollIntoView(item) Exit For End If Next End With Else . . . End If . . .End FunctionThe attached screens show the results of my testing as follows;
- Screen 1 shows the screen without any grouping but filtered to display a limited number of records.
- Screen 2 shows the screen after saving a new record (the green shading is a style applied to the grid to highlight records that have been add/modified in the current session).
- Screen 3 shows the screen with grouping applied and after saving the 2nd new record.
- Screen 4 shows the screen with the grouping removed (note the 2nd new record is now displayed)
The following is the output from the debug statements;
10:08:34 - Adding object to collection10:08:34 - gvWells_DataLoaded10:08:34 - Object located in collection subset10:08:34 - Object located in GridView10:10:23 - gvWells_DataLoaded10:10:38 - Adding object to collection10:10:38 - Object located in collection subset10:11:46 - gvWells_DataLoadedThe entries for 10:08:34 show the statements executed from Screen 2 when the 1st object was added.
The entry for 10:10:23 is when the grouping was applied.
The entry for 10:10:38 is when the 2 object was added (but wasn't displayed in the grid).
The entry for 10:11:46 is when the grouping was removed and the record was then displayed. Any help you can provide on this would be greatly appreciated.
Regards,
Ray
0
Hello Ray,
You can also subscribe for RadGridView.Items.CollectionChanged event and monitor if such an event is raised when a new item has been added.
How is your solution different than mine? Would you please try extending my test solution to be as close to your real case as possible?
According to this ticket's information you use version 2014.1.331, is this correct?
Regards,
Didie
Telerik
You can also subscribe for RadGridView.Items.CollectionChanged event and monitor if such an event is raised when a new item has been added.
How is your solution different than mine? Would you please try extending my test solution to be as close to your real case as possible?
According to this ticket's information you use version 2014.1.331, is this correct?
Regards,
Didie
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.