This is a migrated thread and some comments may be shown as answers.

DataLoaded Event Not Fired When Records Grouped

6 Answers 285 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 29 Apr 2014, 10:57 PM
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;
'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
    Next
End With

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?

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 30 Apr 2014, 12:20 PM
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
 
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.DataLoaded
02.    With gvFooBars
03.        If (.Items.ItemCount > 0) And (moFooBar Is Nothing) Then .SelectedItem = .Items(0)
04.    End With
05.End Sub
06. 
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 = mcolFooBars
11. 
12.    'If there are no existing records create a new object...
13.    If (mcolFooBars.Count = 0) Then moFooBar = New FooBar
14.End Sub
15. 
16.Public Function Save() As Boolean
17.    Dim bSaved As Boolean = False
18.    Dim bNew As Boolean = False
19. 
20.    Const PROC As String = "Save FooBar Record"
21. 
22.    If moFooBar.IsDirty Then
23.        bNew = moFooBar.IsNewRecord
24.        bSaved = FooBarBusiness.Save(moFooBar)
25.         
26.        if bSaved Then
27.            'If this was a new record then add it to the FooBar list...
28.            If bNew Then
29.                '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 Then
36.                    Dim iFooBarId As Integer = moFooBar.FooBarId
37.                    Call LoadRecords(miScenarioId)
38.                    moFooBar = FooBarBusiness.GetRecord(iFooBarId)
39.                End If
40. 
41.                'Select the object in the grid...
42.                With gvFooBars
43.                    For Each item As FooBarView In .Items
44.                        If item.FooBarId = moFooBar.FooBarId Then
45.                            .SelectedItem = item
46.                            .ScrollIntoView(item)
47.                            Exit For
48.                        End If
49.                    Next
50.                End With
51.            Else
52.                .
53.                .
54.                .
55.            End If
56. 
57.            gvFooBars.CalculateAggregates()
58.        End If
59.    End If
60. 
61.    Return bSaved
62.End Function

Line 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
Dimitrina
Telerik team
answered on 01 May 2014, 08:44 AM
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
 
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
Dimitrina
Telerik team
answered on 01 May 2014, 08:45 AM
Hi,

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;

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 With
End Sub
 
 Public 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 Function

The 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 collection
10:08:34 - gvWells_DataLoaded
10:08:34 - Object located in collection subset
10:08:34 - Object located in GridView
10:10:23 - gvWells_DataLoaded
10:10:38 - Adding object to collection
10:10:38 - Object located in collection subset
10:11:46 - gvWells_DataLoaded

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
0
Dimitrina
Telerik team
answered on 05 May 2014, 01:09 PM
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
 
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.
 
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Raymond
Top achievements
Rank 1
Share this question
or