Home Forums WinForms controls Xceed Grid for WinForms Master Detail and Relationship

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17001 |

    I after trying a lot again am not able to produce master/details structure.

    I am in mid of some POC for a new project but am not able to manage it with xceed data grids

    have attached screenshot of what it is visible to me when the data loads in master and detail grid.

    For every row in master, i get all the rows in detail grid.

     

    I fail to understand, should the relation be set at database level or Dataset level or at time when we do schema binding to the master and detail grid.

    need your help in generating code for populating master and detail data from database, adding relationship between the two and binding to master and detail grid.

     

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

    User (Old forums)
    Member
    Post count: 23064

    As long as there is a relationship in the DataSet you are binding to, it does not matter at what level you establish it.

    Can you paste the code you use to generate the DataSet and relationship, and how you bind the grid to it, so I can try to identify the problem?

    Meanwhile, you can look at the following topics in our help documentation, and see if it helps you solve your issue :

    http://doc.xceedsoft.com/products/XceedGrid/Master_Detail.html

    http://doc.xceedsoft.com/products/XceedGrid/Building_a_bound_hierarchical_master_detail_grid.html

     

    Imported from legacy forums. Posted by André (had 2580 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    The problem is the way you bind the grid and the detail grid.  If I take the second snippet you use, your DataSet and the relationship are properly set up.  What you need to do is change this :

                GridControl1.SetDataBinding(ds.Tables(0), “”)
                Dim detail As New DetailGrid
                detail.SetDataBinding(ds.Tables(1), “”) 

    for this :

                GridControl1.SetDataBinding(ds.Tables(0), “”)
                Dim detail As New DetailGrid
                detail.SetDataBinding(ds.Tables(0), “Mater_Child”)

    As you can see, the DataSource on which both the master and the detail grids are bound must be the same.  What changes is the DataMember, in which you need to specify the relationship for the detail grid, and nothing for the master grid.

    In you first scenario, it will not work since there is no relationship, but if you were to add relationships, you would need to do the same, that is, bind the detail grid to the same DataSource of the master grid (which would be dsRemote(0)), and specify the relationship name for the DataMember of each detail grid.

    Imported from legacy forums. Posted by André (had 427 views)

    User (Old forums)
    Member
    Post count: 23064

    You are a GEM dear … Made my life easier, howe:ver have increased my expecataion … means more trouble to you all guys [:)]

    Just a Quickiee … Will this master detail be taken care if my database has got relationship build, rather then setting up relationship after fetching them exceptionally in my code ?

    As you are aware of the concept tha i am trying to put forward to my client is dynamic master detail and sub detail, might like your extened help as well. Thanks again … i am trying to break my head with the complex ones …

     

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

    User (Old forums)
    Member
    Post count: 23064

    Lets say you have a relational DB. It means all relationships are already designed into the DB, and accordingly, when loading a DataSet with data from different DataTable, the relationships between those tables will be automatically generated into the DataSet, and so you can bind the detail grid the same way I showed, that is, DataSource= MasterTable, DataMember=RelationshipName.

    Imported from legacy forums. Posted by André (had 2628 views)

    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)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.