This is a migrated thread and some comments may be shown as answers.

Problem occured in Master and Detail table view in radgridview using windows application

1 Answer 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rangadurai
Top achievements
Rank 1
Rangadurai asked on 14 Sep 2012, 11:45 AM
Hi,

    I am not able to bind the summary and detail datas into the radgridview.I am using two datatables,one is for master and another one is for detail.But i cant able to bind while expanding the grid."In the detail,i want to bind only specified columns such as Mold,Mold_pos_from,mold_pos_to,model,assembly_line_id"
Note:-
        Column Model and Assembly_Line_id must be combo box

I attached my code below:-

  Private Sub CBSEARCH_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBSEARCH.Click
        Try
            intFlag = 1
            Grid_Combo_load()
            dsCastPlan = retrieveData()           
            Grid_Property(1)
            setColumn(dsCastPlan)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
   
     Private Sub Grid_Property(ByVal add_New As Integer)
        'Grid_Combo_load()
        Me.gvBarcodeGen.HorizontalScrollState = Telerik.WinControls.UI.ScrollState.AlwaysShow
        'Grouping()
        'row_summary(add_New)
        'gv_CPS.GroupDescriptors.Expression = "Cast Area"
        gvBarcodeGen.AutoExpandGroups = True
        gvBarcodeGen.GroupExpandAnimationType = Telerik.WinControls.UI.GridExpandAnimationType.Slide
        gvBarcodeGen.EnableSorting = True
        gvBarcodeGen.EnableGrouping = True
        gvBarcodeGen.ShowFilteringRow = False
        'Filter section
        gvBarcodeGen.EnableFiltering = False
        gvBarcodeGen.ShowGroupPanel = False
        gvBarcodeGen.AllowColumnResize = True
        gvBarcodeGen.MasterTemplate.ShowHeaderCellButtons = True
        gvBarcodeGen.MasterTemplate.ShowFilteringRow = False
        'gv_CPS.BestFitColumns()
    End Sub
    Private Sub setColumn(ByVal dscastplan As DataSet)
        Try
         
            Me.gvBarcodeGen.DataSource = dscastplan.Tables(0)          

            Dim childTemplate1 As New GridViewTemplate()
          
            childTemplate1.DataSource = dscastplan.Tables(1)

            childTemplate1.Columns("Mold").Width = 100
            childTemplate1.Columns("Mold").WrapText = True

            childTemplate1.Columns("mold_pos_from").Width = 100
            childTemplate1.Columns("mold_pos_from").WrapText = True

            childTemplate1.Columns("mold_pos_to").Width = 100
            childTemplate1.Columns("mold_pos_to").WrapText = True

            childTemplate1.Columns("Model").Width = 100
            childTemplate1.Columns("Model").WrapText = True

            'childTemplate1.Columns("Caster").Width = 100
            'childTemplate1.Columns("Caster").WrapText = True

            childTemplate1.Columns("assembly_line_id").Width = 100
            childTemplate1.Columns("assembly_line_id").WrapText = True

            childTemplate1.Columns("Status").Width = 100
            childTemplate1.Columns("Status").WrapText = True         

            Me.gvBarcodeGen.MasterTemplate.Templates.Add(childTemplate1)

            Dim relation1 As New GridViewRelation(Me.gvBarcodeGen.MasterTemplate)
            relation1.RelationName = "BenchMold_MoldPosition"
            relation1.ParentColumnNames.Add("bench_id")
            relation1.ChildColumnNames.Add("bench_id")
            relation1.ChildTemplate = childTemplate1
            Me.gvBarcodeGen.Relations.Add(relation1)

        Catch ex As Exception
            Throw ex
        End Try
    End Sub
   
    Private Sub Grid_Combo_load()

        gvBarcodeGen.Columns.Clear()
        gvBarcodeGen.AutoGenerateColumns = False

        Dim BENCH As New GridViewTextBoxColumn
        BENCH.Name = "bench"
        BENCH.HeaderText = "BENCH"
        BENCH.FieldName = "bench"
        BENCH.Width = 100
        BENCH.ReadOnly = True
        gvBarcodeGen.Columns.Add(BENCH)

        Dim SHIFT As New GridViewTextBoxColumn()
        SHIFT.Name = "shift_num"
        SHIFT.HeaderText = "SHIFT NUM"
        SHIFT.FieldName = "shift_num"
        SHIFT.Width = 100
        SHIFT.ReadOnly = True
        gvBarcodeGen.Columns.Add(SHIFT)

        'Dim BENCH As New GridViewComboBoxColumn()
        'BENCH.Name = "BENCH"
        'BENCH.HeaderText = "BENCH"
        'BENCH.DataSource = objCom.Dynamic_Combo_load("bench_id", "Name", "T_SFS_MAS_BENCH ORDER BY NAME")
        'BENCH.ValueMember = "bench_id"
        'BENCH.DisplayMember = "Name"
        'BENCH.FieldName = "BENCH"
        'BENCH.Width = 100
        'BENCH.ReadOnly = True
        'gvBarcodeGen.Columns.Add(BENCH)

        'Dim MoldCombo As New GridViewComboBoxColumn()
        'MoldCombo.Name = "MOLD NAME"
        'MoldCombo.HeaderText = "MOLD NAME"
        ''MoldCombo.DataSource = objCom.Dynamic_Combo_load("cast(mold_type_id as varchar(100)) as mold_type_id", "Name", "T_SFS_MOLD_TYPE ORDER BY NAME")
        'MoldCombo.DataSource = objCom.Dynamic_Combo_load("mold_type_id", "Name", "T_SFS_MOLD_TYPE ORDER BY NAME")
        'MoldCombo.ValueMember = "mold_type_id"
        'MoldCombo.DisplayMember = "Name"
        'MoldCombo.FieldName = "MOLD NAME"
        'MoldCombo.Width = 100
        ''MoldCombo.AutoCompleteMode = AutoCompleteMode.SuggestAppend
        'gvBarcodeGen.Columns.Add(MoldCombo)

        Dim NUM_INSTALLED As New GridViewTextBoxColumn()
        NUM_INSTALLED.Name = "num_installed"
        NUM_INSTALLED.HeaderText = "NUM INSTALLED"
        NUM_INSTALLED.FieldName = "num_installed"
        NUM_INSTALLED.Width = 100
        NUM_INSTALLED.ReadOnly = True
        gvBarcodeGen.Columns.Add(NUM_INSTALLED)

        Dim START_BARCODE As New GridViewTextBoxColumn()
        START_BARCODE.Name = "start_barcode"
        START_BARCODE.HeaderText = "START BARCODE"
        START_BARCODE.FieldName = "start_barcode"
        START_BARCODE.Width = 100
        START_BARCODE.ReadOnly = True
        gvBarcodeGen.Columns.Add(START_BARCODE)

        Dim END_BARCODE As New GridViewTextBoxColumn()
        END_BARCODE.Name = "end_barcode"
        END_BARCODE.HeaderText = "END BARCODE"
        END_BARCODE.FieldName = "end_barcode"
        END_BARCODE.Width = 100
        END_BARCODE.ReadOnly = True
        gvBarcodeGen.Columns.Add(END_BARCODE)

        Dim STATUS As New GridViewTextBoxColumn()
        STATUS.Name = "status"
        STATUS.HeaderText = "STATUS"
        STATUS.FieldName = "status"
        STATUS.Width = 100
        STATUS.ReadOnly = False
        gvBarcodeGen.Columns.Add(STATUS)

 

        Dim MOLD As New GridViewTextBoxColumn()
        MOLD.Name = "Mold"
        MOLD.HeaderText = "MOLD"
        MOLD.FieldName = "Mold"
        MOLD.Width = 100
        MOLD.ReadOnly = False
        ' Me.gvBarcodeGen.MasterTemplate.Templates.Add(childTemplate1)
        gvBarcodeGen.MasterTemplate.Columns.Add(MOLD)

 

 

    End Sub
     Private Sub drawCastPlanDetTable()
        Try

            dtCastPlan_New_0.Columns.Clear()           
            dtCastPlan_New_0.Columns.Add("bench_id", GetType(Integer))
            dtCastPlan_New_0.Columns.Add("bench", GetType(String))          
            dtCastPlan_New_0.Columns.Add("num_installed", GetType(Integer))          
            dtCastPlan_New_0.Columns.Add("assembly_line_id", GetType(Integer))         
            dtCastPlan_New_0.Columns.Add("shift_num", GetType(String))
            dtCastPlan_New_0.Columns.Add("cavity", GetType(Integer))         
            dtCastPlan_New_0.Columns.Add("start_barcode", GetType(String))
            dtCastPlan_New_0.Columns.Add("end_barcode", GetType(String))
            dtCastPlan_New_0.Columns.Add("status", GetType(Integer))         
            dtCastPlan_New_0.Columns.Add("Status_Description", GetType(String))

            dtCastPlan_Det_0.Columns.Clear()          
            dtCastPlan_Det_0.Columns.Add("bench_id", GetType(Integer))
            dtCastPlan_Det_0.Columns.Add("bench", GetType(String))
            dtCastPlan_Det_0.Columns.Add("mold_type_id", GetType(Integer))
            dtCastPlan_Det_0.Columns.Add("Position", GetType(Integer))          
            dtCastPlan_Det_0.Columns.Add("cavity", GetType(Integer))         
            dtCastPlan_Det_0.Columns.Add("Mold", GetType(String))
            dtCastPlan_Det_0.Columns.Add("model", GetType(String))
            dtCastPlan_Det_0.Columns.Add("assembly_line_id", GetType(Integer))
            dtCastPlan_Det_0.Columns.Add("shift", GetType(Integer))

            dtCastPlan_Det_0.Columns.Add("mold_pos_from", GetType(Integer))
            dtCastPlan_Det_0.Columns.Add("mold_pos_to", GetType(Integer))
            dtCastPlan_Det_0.Columns.Add("barcode", GetType(String))
            dtCastPlan_Det_0.Columns.Add("status", GetType(Integer))
          
            dtCastPlan_Det_0.AcceptChanges()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

Private Function retrieveData(Optional ByVal Flag As Integer = 0) As DataSet
        Try
           
            drawCastPlanDetTable()

            dtCastPlan_New = objclsBarcodeGen.getPlanningData(RadDateTimePicker1.Value, Convert.ToInt32(ddlBench.SelectedValue), Convert.ToInt32(txtShiftFrom.Text), Convert.ToInt32(txtShiftTo.Text), Convert.ToInt32(ddlProcessOwner.SelectedValue), Flag)

            dtCastPlan_New.Columns.Add("Status_Description", GetType(String))

            Dim drValid As DataRow()
            Dim drValid0 As DataRow()
            Dim drNew As DataRow

            dtCastPlan_New_0 = dtCastPlan_New.Clone
            For cnt As Integer = 0 To dtCastPlan_New.Rows.Count - 1
                drValid = dtCastPlan_New.Select("Bench_id=" & dtCastPlan_New.Rows(cnt).Item("Bench_id") & " and shift_num=" & dtCastPlan_New.Rows(cnt).Item("shift_num") & "")
                If drValid.Length > 0 Then
                    If Not dtCastPlan_New_0.Rows.Count > 0 Then
                        drNew = dtCastPlan_New_0.NewRow
                        drNew("bench_id") = drValid(0).Item("bench_id")
                        drNew("bench") = drValid(0).Item("bench")                      
                        drNew("num_installed") = drValid(0).Item("num_installed")                      
                        drNew("assembly_line_id") = drValid(0).Item("assembly_line_id")                    
                        drNew("shift_num") = drValid(0).Item("shift_num")
                        drNew("cavity") = drValid(0).Item("cavity")
                        drNew("start_barcode") = drValid(0).Item("start_barcode")
                        drNew("end_barcode") = drValid(0).Item("end_barcode")
                        drNew("status") = drValid(0).Item("status")                      
                        drNew("Status_Description") = String.Empty
                        dtCastPlan_New_0.Rows.Add(drNew)
                    Else
                        drValid0 = dtCastPlan_New_0.Select("Bench_id=" & dtCastPlan_New.Rows(cnt).Item("Bench_id") & " and shift_num=" & dtCastPlan_New.Rows(cnt).Item("shift_num") & "")
                        If Not drValid0.Length > 0 Then
                            drNew = dtCastPlan_New_0.NewRow                          
                            drNew("bench_id") = drValid(0).Item("bench_id")
                            drNew("bench") = drValid(0).Item("bench")                           
                            drNew("num_installed") = drValid(0).Item("num_installed")                          
                            drNew("assembly_line_id") = drValid(0).Item("assembly_line_id")                         
                            drNew("shift_num") = drValid(0).Item("shift_num")
                            drNew("cavity") = drValid(0).Item("cavity")
                            drNew("start_barcode") = drValid(0).Item("start_barcode")
                            drNew("end_barcode") = drValid(0).Item("end_barcode")
                            drNew("status") = drValid(0).Item("status")                         
                            dtCastPlan_New_0.Rows.Add(drNew)
                        End If
                    End If
                End If

            Next
            dtCastPlan_New_0.AcceptChanges()

            Dim drChild As DataRow

            For iChdCnt As Integer = 0 To dtCastPlan_New.Rows.Count - 1

                For iCavityCnt As Integer = 1 To dtCastPlan_New.Rows(iChdCnt).Item("cavity")
                    drChild = dtCastPlan_Det_0.NewRow                   
                    drChild("bench_id") = dtCastPlan_New.Rows(iChdCnt).Item("bench_id")
                    drChild("bench") = dtCastPlan_New.Rows(iChdCnt).Item("bench")
                    drChild("mold_type_id") = dtCastPlan_New.Rows(iChdCnt).Item("mold_type_id")
                    drChild("Position") = dtCastPlan_New.Rows(iChdCnt).Item("mold_position")                   
                    drChild("cavity") = iCavityCnt                   
                    drChild("Mold") = dtCastPlan_New.Rows(iChdCnt).Item("Mold")
                    drChild("model") = dtCastPlan_New.Rows(iChdCnt).Item("model")
                    drChild("assembly_line_id") = dtCastPlan_New.Rows(iChdCnt).Item("assembly_line_id")
                    drChild("shift") = dtCastPlan_New.Rows(iChdCnt).Item("shift_num")
                    drChild("mold_pos_from") = 0
                    drChild("mold_pos_to") = 0
                    drChild("barcode") = String.Empty
                    drChild("status") = DBNull.Value                 
                    dtCastPlan_Det_0.Rows.Add(drChild)
                Next

            Next

            dtCastPlan_Det_0.AcceptChanges()

            Dim intInstallMold, intMoldPosFrm, intMoldPosTo As Integer
            Dim drInstallValid As DataRow()
            For iRowCnt As Integer = 0 To dtCastPlan_New_0.Rows.Count - 1
                intInstallMold = 0
                intMoldPosFrm = 1
                intMoldPosTo = 1

                drInstallValid = dtCastPlan_New.Select("Bench_id=" & dtCastPlan_New_0.Rows(iRowCnt).Item("Bench_id") & " and shift_num=" & dtCastPlan_New_0.Rows(iRowCnt).Item("shift_num") & "")
                If drInstallValid.Length > 0 Then
                    For i As Integer = 0 To drInstallValid.Length - 1
                        intInstallMold = intInstallMold + drInstallValid(i).Item("num_installed")
                        intMoldPosTo = intMoldPosTo + i
                    Next
                    dtCastPlan_New_0.Rows(iRowCnt).Item("num_installed") = intInstallMold
                    dtCastPlan_New_0.Rows(iRowCnt).Item("mold_pos_from") = intMoldPosFrm
                    dtCastPlan_New_0.Rows(iRowCnt).Item("mold_pos_to") = intMoldPosTo
                End If
            Next
            dtCastPlan_New_0.AcceptChanges()

            dsCastPlan.Tables.Clear()
            dsCastPlan.Tables.Add(dtCastPlan_New_0)
            dsCastPlan.Tables(0).TableName = "BenchMold"
            dsCastPlan.Tables.Add(dtCastPlan_Det_0)
            dsCastPlan.Tables(1).TableName = "MoldPosition"

            lblLastBarcode.Text = objclsBarcodeGen.getLastBarcode()
            Return dsCastPlan
        Catch ex As Exception
            Throw ex
        End Try
    End Function




Pls help me

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 19 Sep 2012, 08:37 AM
Hello Rangadurai,

Thank you for writing.

In your example you were not able to create the binding because your relation counts on the "bench_id" column which did not exist in the MasterTemplate. Once I added it the binding works correctly. If you do not want to see this column in the grid, simply set its IsVisible property to false.

There are two ways to populate the grid when using bound mode:
1. Create and add the columns manually with the respective FieldName set and assign the DataSource to the grid while the AutoGenerateColumns is false. This approach you took to populate the MasterTemplate of the grid.
2. Allow the grid to automatically generate its columns by simply setting the DataSource and by leaving the default value (true) of the AutoGenerateColumns property. Once the grid is bound, you can hide, replace, modify the columns and their settings. This approach is taken for the childTemplate1 in the attached project.

I hope that you find this information useful. Let me know if you have any additional questions.

Greetings,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Rangadurai
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or