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

 

 Hi,add find below the codee that i am using… pls bear with me … i am not a professional programmer, but just help in proof of concepotd to client for new project and i love this grid alot., All my attempt so far didnt worked out and then decided to let go, however i am again into action with this grid.

 It is out of this context, however will like to hear how best i can do this.

I am trying to fetch data at runtime, my config table will have the queries and the sub queries and further sub-sub queries, with the relation ship between each query to the master.However my tables will only have primary key.

At run time i am trying to add a control and set child parent relationship…

 

IF youy are trying to simulate this scenario then suggest me the best piece of code which will siffice my POC needs.Pls write comments against each action. Thanks in advance for this. 

Dim dsLocal As DataSet
Dim dsRemote(), dstemp As DataSet
Dim isUpdateable(), isInseretable() As Boolean

tmpQry = “Select B.*,A.Theme from tvw_DG_SQLQry A ,tvw_DG_QryDetails B where A.SQLQueryID = B.SQLQueryID_grp and A.QueryName = ‘” & strSqlTitle & “‘”
dsLocal = modDataAccess.ExecuteQryWithData(objGrdLocalConn, tmpQry, “Load”) ‘ returns a dataset

intTbl = dsLocal.Tables(0).Rows.Count
ReDim Preserve dsRemote(intTbl)
ReDim Preserve isInseretable(intTbl)
ReDim Preserve isUpdateable(intTbl)
ReDim Preserve strChildTblName(intTbl)

strTheme = dsLocal.Tables(0).Rows(0).Item(8).ToString ‘ theme to apply to the grid

For i = 0 To intTbl – 1
 qryRem = dsLocal.Tables(0).Rows(i).Item(3).ToString
 strChildTblName(i) = dsLocal.Tables(0).Rows(i).Item(4).ToString
 isInseretable(i) = IIf(UCase(dsLocal.Tables(0).Rows(0).Item(7).ToString) = “YES”, True, False)   ‘if true allow grid insert else grid is read only
 isUpdateable(i) = IIf(UCase(dsLocal.Tables(0).Rows(0).Item(6).ToString) = “YES”, True, False)  ‘ if updatable then allow dataset updates back to database
 dsRemote(i) = modDataAccess.ExecuteQryWithData(objGrdRemConn, qryRem, strChildTblName(i))
Next

 GridControl1.BeginInit()

            With GridControl1
                .DataSource = dsRemote(0)
                .DataMember = strChildTblName(0)
                .SynchronizeDetailGrids = True
            End With

            If isInseretable(0) Then
                GridControl1.HeaderRows.Add(New InsertionRow())
                Dim m_spacerRow = New SpacerRow()
                m_spacerRow.Height = 4
            End If

            Dim detail(intTbl) As DetailGrid
            ‘ReDim detail(intTbl – 2)
            For i = 1 To intTbl – 1
                detail(i – 1) = New DetailGrid
                detail(i – 1).HeaderRows.Add(New ColumnManagerRow())
                detail(i – 1).DataSource = dsRemote(i)
                detail(i – 1).DataMember = strChildTblName(i)
                Debug.Print(i)
            Next

            If intTbl > 1 Then
                GridControl1.DetailGridTemplates.Add(detail(0))
            End If

            ‘Dim detail(intTbl) As DetailGrid
            ‘detail(0) = New DetailGrid
            ‘detail(0).HeaderRows.Add(New ColumnManagerRow())
            ‘detail(0).DataSource = dsRemote(1)
            ‘detail(0).DataMember = “Remote_1”
            ‘GridControl1.DetailGridTemplates.Add(detail(0))

 

            applyStype(strTheme)

 

 GridControl1.EndInit()

 

 

Below is another piece of code that i tried for which u have the screenshot of the output…—————————————————————————————–

Try

            Dim ds As New DataSet
            Dim ds1 As New DataSet

            Dim adaptor As New SqlClient.SqlDataAdapter
            Dim adaptor1 As New SqlClient.SqlDataAdapter
            adaptor = New SqlClient.SqlDataAdapter(“select * from msdb..sysjobs”, objRemConn)
            adaptor1 = New SqlClient.SqlDataAdapter(“select * from msdb..sysjobhistory”, objRemConn)

            adaptor.Fill(ds, “Jobs”)
            adaptor1.Fill(ds, “History”)
            Dim dc1(1) As DataColumn

            dc1(0) = ds.Tables(“Jobs”).Columns(“job_id”)
            dc1(1) = ds.Tables(“History”).Columns(“job_id”)
            ds.Tables(0).PrimaryKey = dc1

            Dim data_rel As New DataRelation(“Master_Child”, dc1(0), dc1(1))
            ds.Relations.Add(data_rel)

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

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

            GridControl1.BeginInit()

            GridControl1.SetDataBinding(ds.Tables(0), “”)

 

            Dim detail As New DetailGrid
            ‘ReDim detail(intTbl – 2)
            detail.SetDataBinding(ds.Tables(1), “”)
            detail.Collapsed = True
            detail.HeaderRows.Add(New ColumnManagerRow())

            GridControl1.DetailGridTemplates.Add(detail)

            applyStype(“WinXp”)

 

            GridControl1.EndInit()

  

        Catch ex As Exception
            ‘MsgBox(ex.Message)
           
        End Try

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