vb.netdevexpressgridcontroldevexpress-windows-ui

Tree View Datagridview in devexpress


I tried many times to create a master view of the table along with its details and visualize that in a Gridcontrol (from Devexpress) here is the code *I do not want to rely on the automatic generation of codes by Devexpress designer!

        ' DEFINE A DATASET TO HOLD TABLES INSIDE
        Dim dataset As New DataSet

        'IF THE CONNECTION IS POSSIBLE THEN PROCCEED
        If sqlcontrol.HasConnection Then
            ' SELECT ALL RECORDS FROM THE SUPPLIERS TABLE (MASTER TABLE)
            sqlcontrol.ExecQuery("SELECT * FROM [Suppliers]")
            ' FILL IN THAT TABLE INTO THE DATASET
            dataset.Tables.Add(sqlcontrol.SQLdatatable)
            ' SELECT ALL RECORDS FROM THE SUPPLIERSPERSONNEL (DETAIL TABLE)
            sqlcontrol.ExecQuery("SELECT * FROM [SuppliersPersonnel]")
            'FILL IN THAT TABLE INTO THE DATASET
            dataset.Tables.Add(sqlcontrol.SQLdatatable)



            'INVOKE THE BINDING SOURCE INTO THE GRIDVIEW
            Me.GridControl1.DataSource = dataset
        End If

hopefully it worked but not like a master-detail view. it showed every table on its own.


Solution

  • The Dataset itself indeed contains the tables, yet the relations between tables are missing and did not retrieved from the SQL tables, hence why this relationship needs to be added inside the Dataset in VB. so the code is like the following:

        ' DEFINE A DATASET TO HOLD TABLES INSIDE
        Dim dataset As New DataSet
    
        'IF THE CONNECTION IS POSSIBLE THEN PROCCEED
        If sqlcontrol.HasConnection Then
            ' SELECT ALL RECORDS FROM THE SUPPLIERS TABLE (MASTER TABLE)
            sqlcontrol.ExecQuery("SELECT * FROM [Suppliers]")
            ' FILL IN THAT TABLE INTO THE DATASET
            dataset.Tables.Add(sqlcontrol.SQLdatatable)
            ' SELECT ALL RECORDS FROM THE SUPPLIERSPERSONNEL (DETAIL TABLE)
            sqlcontrol.ExecQuery("SELECT * FROM [SuppliersPersonnel]")
            'FILL IN THAT TABLE INTO THE DATASET
            dataset.Tables.Add(sqlcontrol.SQLdatatable)
    
           'Add the relation to the dataset
            dataset.relations.add("CustomRelation", 
                        dataset.tables(0).columns(0),
                           dataset.tables(1).columns(1), false)
    
            'INVOKE THE BINDING SOURCE INTO THE GRIDVIEW
            Me.GridControl1.DataSource = dataset
        End If
    

    By such way, the Gridcontrol works as expected !