Home Forums WinForms controls Xceed Grid for WinForms Master detail using collections Reply To: Master detail using collections

User (Old forums)
Member
Post count: 23064

I find a solution.  I create as many dataTable as many detail grid is opened.  Don’t know if there a better way to do the same thing.  I don’t really like my code, but this works, and it’s fast. (Note many lines are removed)

Public Class frm_catalog

    Dim catalogPriceDT As Collection ‘ gestionSEDataSet.catalog_PriceDataTable
    Dim catalogPriceBS As Collection ‘ BindingSource
    Dim catalogPriceTA As gestionSEDataSetTableAdapters.catalog_PriceTableAdapter

    Public Sub New()
        InitializeComponent()

        catalogPriceTA = New gestionSEDataSetTableAdapters.catalog_PriceTableAdapter
        catalogPriceDT = New Collection
        catalogPriceBS = New Collection
    End Sub

    Private Sub template_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Catalog_listTableAdapter.FillByIdCie(Me.GestionSEDataSet.catalog_list, getIdCie())

            With GridCatalog
                .BeginInit()
       
                .DetailGridTemplates(0).Collapsed = True
                .SynchronizeDetailGrids = False
                AddHandler .DetailGridTemplates(0).CollapsedChanged, AddressOf bindDetailGrid
                .UpdateDetailGrids()
                end with
        end sub
       
    Private Sub bindDetailGrid(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim LocalDetail As Xceed.Grid.DetailGrid

        LocalDetail = DirectCast(sender, Xceed.Grid.DetailGrid)
        If Not LocalDetail.Collapsed Then
            Try
                Dim DT As gestionSEDataSet.catalog_PriceDataTable = New gestionSEDataSet.catalog_PriceDataTable

                Dim BS As BindingSource = New BindingSource
                BS.DataSource = DT
                catalogPriceTA.FillByIdCatalog(DT, LocalDetail.ParentDataRow.Cells(“id_catalog”).Value)

                ‘ default value for linking field
                DT.Columns(“id_catalog”).DefaultValue = LocalDetail.ParentDataRow.Cells(“id_catalog”).Value

                catalogPriceDT.Add(DT)
                catalogPriceBS.Add(BS)

                With LocalDetail
                    .SetDataBinding(BS, Nothing)
                                end with

            Catch ex As Exception
                Call ErrorManagement(Me.Name, “detailGridTemplate1_CollapsedChanged”, ex.Message)
            End Try
        End If
    End Sub

    Private Sub save()
        Me.Validate()
        Me.Catalog_listBindingSource.EndEdit()
        Me.Catalog_listTableAdapter.Update(Me.GestionSEDataSet.catalog_list)

        For Each BS As BindingSource In catalogPriceBS
            BS.EndEdit()
        Next

        For Each DT As gestionSEDataSet.catalog_PriceDataTable In catalogPriceDT
            catalogPriceTA.Update(DT)
        Next

    End Sub

Imported from legacy forums. Posted by Daniel (had 496 views)