Home Forums WinForms controls Xceed Grid for WinForms Master Detail and Relationship Reply To: Master Detail and Relationship

User (Old forums)
Member
Post count: 23064

For those who are new to the grid —

 Thanks to Andre …

 

 Private Sub initgrid_test()
        Try

            Dim ds As New DataSet
            Dim ds1 As New DataSet

            Dim adaptor As New SqlClient.SqlDataAdapter
            Dim adaptor1 As New SqlClient.SqlDataAdapter
            Dim adaptor2 As New SqlClient.SqlDataAdapter
            Dim adaptor3 As New SqlClient.SqlDataAdapter
            Dim adaptor4 As New SqlClient.SqlDataAdapter

            adaptor = New SqlClient.SqlDataAdapter(“select * from msdb..sysjobs order by job_id”, objRemConn)
            adaptor1 = New SqlClient.SqlDataAdapter(“select * from   msdb..SysJobSteps  order by job_id”, objRemConn)
            adaptor2 = New SqlClient.SqlDataAdapter(“select * from   msdb..SysJobSchedules  order by job_id”, objRemConn)
            adaptor3 = New SqlClient.SqlDataAdapter(“select * from msdb..sysjobactivity order by last_executed_step_date desc”, objRemConn)
            adaptor4 = New SqlClient.SqlDataAdapter(“select * from   msdb..sysjobhistory  order by job_id, instance_id desc”, objRemConn)

 

            adaptor.Fill(ds, “Jobs”)
            adaptor1.Fill(ds, “Steps”)
            adaptor2.Fill(ds, “Schedule”)
            adaptor3.Fill(ds, “Activity”)
            adaptor4.Fill(ds, “History”)

            Dim dc1(4) As DataColumn

            dc1(0) = ds.Tables(“Jobs”).Columns(“job_id”)
            dc1(1) = ds.Tables(“Steps”).Columns(“job_id”)
            dc1(2) = ds.Tables(“Schedule”).Columns(“job_id”)
            dc1(3) = ds.Tables(“Activity”).Columns(“job_id”)
            dc1(4) = ds.Tables(“History”).Columns(“job_id”)

            ‘ds.Tables(0).PrimaryKey = dc1

            Dim data_rel0 As New DataRelation(“Master_Child”, dc1(0), dc1(1))
            Dim data_rel1 As New DataRelation(“Master_Child1”, dc1(0), dc1(2))
            Dim data_rel2 As New DataRelation(“Master_Child2”, dc1(0), dc1(3))
            Dim data_rel3 As New DataRelation(“Master_Child3”, dc1(0), dc1(4))
            ‘ Dim data_rel4 As New DataRelation(“Master_Child4”, dc1(0), dc1(1))

            ds.Relations.Add(data_rel0)
            ds.Relations.Add(data_rel1)
            ds.Relations.Add(data_rel2)
            ds.Relations.Add(data_rel3)
            ‘ds.Relations.Add(data_rel4)

            ‘ds.Tables(“Jobs”).PrimaryKey = dc1

            ‘ Bind the DataGrid to the DataSet.
            ‘dgContacts.DataSource = m_DataSet

            GridControl1.BeginInit()

            GridControl1.SetDataBinding(ds.Tables(0), “”)
            Debug.Print(“table 1 – row count : ” & ds.Tables(0).Rows.Count)

            Dim detail As New DetailGrid

            GridControl1.DetailGridTemplates.Add(detail)
            ‘ReDim detail(intTbl – 2)
            detail.SetDataBinding(ds.Tables(0), “Master_Child”)
            detail.Collapsed = True
            detail.HeaderRows.Add(New ColumnManagerRow())

            Dim detail1 As New DetailGrid

            GridControl1.DetailGridTemplates.Add(detail1)
            ‘ReDim detail(intTbl – 2)
            detail1.SetDataBinding(ds.Tables(0), “Master_Child1”)
            detail1.Collapsed = True
            detail1.HeaderRows.Add(New ColumnManagerRow())

            Dim detail2 As New DetailGrid

            detail1.DetailGridTemplates.Add(detail2)
            ‘ReDim detail(intTbl – 2)
            detail2.SetDataBinding(ds.Tables(0), “Master_Child2”)
            detail2.Collapsed = True
            detail2.HeaderRows.Add(New ColumnManagerRow())

            Dim detail3 As New DetailGrid

            GridControl1.DetailGridTemplates.Add(detail3)
            ‘ReDim detail(intTbl – 2)
            detail3.SetDataBinding(ds.Tables(0), “Master_Child3”)
            detail3.Collapsed = True
            detail3.HeaderRows.Add(New ColumnManagerRow())

 

            applyStype(“WinXp”)

            GridControl1.EndInit()

        Catch ex As Exception
            MsgBox(ex.Message)

            GridControl1.EndInit()
        End Try
    End Sub

Imported from legacy forums. Posted by Credits (had 3930 views)