Nested table shows only header columns w/out records

After binding the datagrid my code goes to a Sub called "AddNestedTables" then for each DetailsViewExpandind it assigns the DetailsViewDataSource. The result is always an empty table
Private Sub AddNestedTables()
        Dim gridViewDefinition1 = New GridViewDefinition()
        gridViewDefinition1.RelationalColumn = "ClientID"
        gridViewDefinition1.DataGrid = New SfDataGrid() With {
            .Name = "FirstLevelNestedGrid1",
            .AutoGenerateColumns = True,
            .AutoGenerateRelations = False}

        Dim db As New AgendaModelDataContext(Me.ConnectionString)
        Dim Telephones = From T In db.AxNomiTel Where T.id_anagrafe > 0 Take 1

        gridViewDefinition1.DataGrid.DataSource = Telephones

        SfDataGrid1.DetailsViewDefinitions.Add(gridViewDefinition1)
End Sub
Private Sub SfDataGrid1_DetailsViewExpanding(sender As Object, e As DetailsViewExpandingEventArgs) Handles SfDataGrid1.DetailsViewExpanding

        e.DetailsViewDataSource.Clear()

        Dim db As New ModelDataContext(Me.ConnectionString)
'Here I get the ID from the array element 22 and it's ok, just for the test purpose
        Dim Id As Integer = CInt(DirectCast(e.Record, System.Data.DataRowView).Row.ItemArray(22))

        Dim Telephones = From T In db.Clients Where T.ClientID = Id 

        If Telephones.Any Then
            e.DetailsViewDataSource.Add("Telefoni", Telephones)
        End If
    End Sub



I can't understand why it doesn't work, the grid shows the table headers on expanding but without data
I tried to convert records in array and lists but the result is always the same

3 Replies

AA Arulraj A Syncfusion Team August 27, 2018 12:15 PM UTC

Hi Karim, 

Thanks for contacting Syncfusion support. 

From the code you have provided, we have found that the key value for adding the DetailsViewDataSource  within the DetailsViewExpanding  event and the value of the RelationalColumn property of the GridViewDefinition is not same. Provide same value for the Key and the ReletonalColumn name. 

Please refer to the following code example and sample. 
Code Example: 
Dim viewDefinition As New GridViewDefinition() 
viewDefinition.RelationalColumn = "OrderDetails" 
Dim firstLevelSourceDataGrid As New SfDataGrid() 
firstLevelSourceDataGrid.AutoSizeColumnsMode = AutoSizeColumnsMode.Fill 
viewDefinition.DataGrid = firstLevelSourceDataGrid 
firstLevelSourceDataGrid.AutoGenerateColumns = True 
Me.sfDataGrid1.DetailsViewDefinitions.Add(viewDefinition) 
 
Me.sfDataGrid1.HideEmptyGridViewDefinition = True 
 
AddHandler Me.sfDataGrid1.DetailsViewExpanding, AddressOf sfDataGrid1_DetailsViewExpanding 
 
Private Sub sfDataGrid1_DetailsViewExpanding(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.DetailsViewExpandingEventArgs) 
       e.DetailsViewDataSource.Clear() 
       e.DetailsViewDataSource.Add("OrderDetails", Me.GetDataTable().DefaultView) 
End Sub 

 

Arulraj A 



KE Karim El Saidi August 28, 2018 06:19 AM UTC

Hi,

Thank you so much, it works perfectly according to your instructions.


AA Arulraj A Syncfusion Team August 28, 2018 06:33 AM UTC

Hi Karim, 

We are glad to know that the problem has been resolved at your end. Please let us know if you have any further queries on this, we are happy to help you. 

Regards, 
Arulraj A 


Loader.
Up arrow icon