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

Template summary Questions

4 Answers 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mohammad
Top achievements
Rank 1
Mohammad asked on 13 Oct 2013, 03:18 PM
I want to know how to :
1- move template part to make value column under the net effect column in parent row.
2- get template summary value ...I couldn't read it.
3- recalculate net effects column, so the net value column on same time of template summary calculated.

thank you very much

best regards

4 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 16 Oct 2013, 01:45 PM
Hello Mohammad,

Thank you for contacting us.

The implementation in this case very much depends on what is your data source. If your data source is a business object every object can have a property which calculates the net value of its children. By implementing the INotifyPropertChanged your main object can listen for property changes and recalculate that property.

If this is not suitable for you, I would recommend you send me a sample project which will help me provide you with more adequate support.

Let me know If I can be of further assistance.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Mohammad
Top achievements
Rank 1
answered on 17 Oct 2013, 07:35 AM
Hello George 

Thank you for your response.
there is any way to upload my project ?

thanks

regards

0
Mohammad
Top achievements
Rank 1
answered on 19 Oct 2013, 03:05 PM
Hello George 

I Can't upload my project , so let's try another thing
Project steps :
1- Make new windows form project using visual studio 2012.
2- put new Radgridview on form and change the name to : GVTransactions.
3- Add this code instead of form designer code starting with private sub InitializeComponent:

   
Private Sub InitializeComponent()<br>
        Dim GridViewTextBoxColumn1 As Telerik.WinControls.UI.GridViewTextBoxColumn = New Telerik.WinControls.UI.GridViewTextBoxColumn()<br>
        Dim GridViewTextBoxColumn2 As Telerik.WinControls.UI.GridViewTextBoxColumn = New Telerik.WinControls.UI.GridViewTextBoxColumn()<br>
        Dim GridViewDecimalColumn1 As Telerik.WinControls.UI.GridViewDecimalColumn = New Telerik.WinControls.UI.GridViewDecimalColumn()<br>
        Dim GridViewDecimalColumn2 As Telerik.WinControls.UI.GridViewDecimalColumn = New Telerik.WinControls.UI.GridViewDecimalColumn()<br>
        Dim GridViewTextBoxColumn3 As Telerik.WinControls.UI.GridViewTextBoxColumn = New Telerik.WinControls.UI.GridViewTextBoxColumn()<br>
        Dim GridViewTextBoxColumn4 As Telerik.WinControls.UI.GridViewTextBoxColumn = New Telerik.WinControls.UI.GridViewTextBoxColumn()<br>
        Dim GridViewTextBoxColumn5 As Telerik.WinControls.UI.GridViewTextBoxColumn = New Telerik.WinControls.UI.GridViewTextBoxColumn()<br>
        Dim GridViewTextBoxColumn6 As Telerik.WinControls.UI.GridViewTextBoxColumn = New Telerik.WinControls.UI.GridViewTextBoxColumn()<br>
        Dim GridViewCommandColumn1 As Telerik.WinControls.UI.GridViewCommandColumn = New Telerik.WinControls.UI.GridViewCommandColumn()<br>
        Me.GVTransactions = New Telerik.WinControls.UI.RadGridView()<br>
        Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()<br>
        Me.Panel1 = New System.Windows.Forms.Panel()<br>
        Me.Button1 = New System.Windows.Forms.Button()<br>
        CType(Me.GVTransactions, System.ComponentModel.ISupportInitialize).BeginInit()<br>
        CType(Me.GVTransactions.MasterTemplate, System.ComponentModel.ISupportInitialize).BeginInit()<br>
        Me.TableLayoutPanel1.SuspendLayout()<br>
        Me.Panel1.SuspendLayout()<br>
        Me.SuspendLayout()<br>
        '<br>
        'GVTransactions<br>
        '<br>
        Me.GVTransactions.Dock = System.Windows.Forms.DockStyle.Fill<br>
        Me.GVTransactions.Location = New System.Drawing.Point(3, 3)<br>
        '<br>
        'GVTransactions<br>
        '<br>
        Me.GVTransactions.MasterTemplate.AllowAddNewRow = False<br>
        Me.GVTransactions.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill<br>
        GridViewTextBoxColumn1.HeaderText = "Item_code"<br>
        GridViewTextBoxColumn1.Name = "Item_code"<br>
        GridViewTextBoxColumn1.ReadOnly = True<br>
        GridViewTextBoxColumn1.Width = 85<br>
        GridViewTextBoxColumn2.HeaderText = "Item name"<br>
        GridViewTextBoxColumn2.Name = "Item_name"<br>
        GridViewTextBoxColumn2.ReadOnly = True<br>
        GridViewTextBoxColumn2.Width = 88<br>
        GridViewDecimalColumn1.HeaderText = "Item Quantity"<br>
        GridViewDecimalColumn1.Minimum = New Decimal(New Integer() {0, 0, 0, 0})<br>
        GridViewDecimalColumn1.Name = "Item_qty"<br>
        GridViewDecimalColumn1.Width = 109<br>
        GridViewDecimalColumn2.HeaderText = "Item price"<br>
        GridViewDecimalColumn2.Minimum = New Decimal(New Integer() {0, 0, 0, 0})<br>
        GridViewDecimalColumn2.Name = "Item_Price"<br>
        GridViewDecimalColumn2.Width = 82<br>
        GridViewTextBoxColumn3.HeaderText = "Total"<br>
        GridViewTextBoxColumn3.Name = "Total"<br>
        GridViewTextBoxColumn3.ReadOnly = True<br>
        GridViewTextBoxColumn3.Width = 47<br>
        GridViewTextBoxColumn4.HeaderText = "Effects Net"<br>
        GridViewTextBoxColumn4.Name = "Effects_net"<br>
        GridViewTextBoxColumn4.ReadOnly = True<br>
        GridViewTextBoxColumn4.Width = 88<br>
        GridViewTextBoxColumn5.HeaderText = "Net After Effects"<br>
        GridViewTextBoxColumn5.Name = "Net_After_Effects"<br>
        GridViewTextBoxColumn5.ReadOnly = True<br>
        GridViewTextBoxColumn5.Width = 127<br>
        GridViewTextBoxColumn6.HeaderText = "Transaction_id"<br>
        GridViewTextBoxColumn6.IsVisible = False<br>
        GridViewTextBoxColumn6.Name = "Transaction_id"<br>
        GridViewTextBoxColumn6.Width = 46<br>
        GridViewCommandColumn1.HeaderText = "Add Effect"<br>
        GridViewCommandColumn1.Name = "AddEffect"<br>
        GridViewCommandColumn1.Width = 171<br>
        Me.GVTransactions.MasterTemplate.Columns.AddRange(New Telerik.WinControls.UI.GridViewDataColumn() {GridViewTextBoxColumn1, GridViewTextBoxColumn2, GridViewDecimalColumn1, GridViewDecimalColumn2, GridViewTextBoxColumn3, GridViewTextBoxColumn4, GridViewTextBoxColumn5, GridViewTextBoxColumn6, GridViewCommandColumn1})<br>
        Me.GVTransactions.MasterTemplate.EnableGrouping = False<br>
        Me.GVTransactions.Name = "GVTransactions"<br>
        Me.GVTransactions.Size = New System.Drawing.Size(811, 498)<br>
        Me.GVTransactions.TabIndex = 0<br>
        Me.GVTransactions.Text = "RadGridView1"<br>
        '<br>
        'TableLayoutPanel1<br>
        '<br>
        Me.TableLayoutPanel1.ColumnCount = 1<br>
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100.0!))<br>
        Me.TableLayoutPanel1.Controls.Add(Me.GVTransactions, 0, 0)<br>
        Me.TableLayoutPanel1.Controls.Add(Me.Panel1, 0, 1)<br>
        Me.TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill<br>
        Me.TableLayoutPanel1.Location = New System.Drawing.Point(0, 0)<br>
        Me.TableLayoutPanel1.Name = "TableLayoutPanel1"<br>
        Me.TableLayoutPanel1.RowCount = 2<br>
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 90.0!))<br>
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10.0!))<br>
        Me.TableLayoutPanel1.Size = New System.Drawing.Size(817, 561)<br>
        Me.TableLayoutPanel1.TabIndex = 1<br>
        '<br>
        'Panel1<br>
        '<br>
        Me.Panel1.Controls.Add(Me.Button1)<br>
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill<br>
        Me.Panel1.Location = New System.Drawing.Point(3, 507)<br>
        Me.Panel1.Name = "Panel1"<br>
        Me.Panel1.Size = New System.Drawing.Size(811, 51)<br>
        Me.Panel1.TabIndex = 1<br>
        '<br>
        'Button1<br>
        '<br>
        Me.Button1.Location = New System.Drawing.Point(9, 3)<br>
        Me.Button1.Name = "Button1"<br>
        Me.Button1.Size = New System.Drawing.Size(114, 23)<br>
        Me.Button1.TabIndex = 0<br>
        Me.Button1.Text = "Add Item"<br>
        Me.Button1.UseVisualStyleBackColor = True<br>
        '<br>
        'Form1<br>
        '<br>
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br>
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br>
        Me.ClientSize = New System.Drawing.Size(817, 561)<br>
        Me.Controls.Add(Me.TableLayoutPanel1)<br>
        Me.Name = "Form1"<br>
        Me.Text = "Form1"<br>
        CType(Me.GVTransactions.MasterTemplate, System.ComponentModel.ISupportInitialize).EndInit()<br>
        CType(Me.GVTransactions, System.ComponentModel.ISupportInitialize).EndInit()<br>
        Me.TableLayoutPanel1.ResumeLayout(False)<br>
        Me.Panel1.ResumeLayout(False)<br>
        Me.ResumeLayout(False)<br>
<br>
    End Sub<br>
    Friend WithEvents GVTransactions As Telerik.WinControls.UI.RadGridView<br>
    Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel<br>
    Friend WithEvents Panel1 As System.Windows.Forms.Panel<br>
    Friend WithEvents Button1 As System.Windows.Forms.Button <br>



4- add this code to your form to make grid works:
<br>
Imports Telerik.WinControls.UI<br>
<br>
Public Class Form1<br>
    Dim WithEvents TmpEff As GridViewTemplate<br>
    '----------------------------------------------------------------------<br>
    Dim WithEvents EffLstCol As GridViewTextBoxColumn<br>
    Dim Effrelation As GridViewRelation<br>
    Dim EffTemplloaded As Boolean = False<br>
    Dim WithEvents colEffInPer As GridViewDecimalColumn<br>
    Dim EffValue As GridViewDecimalColumn<br>
    Dim SmmInfo As GridViewSummaryRowInfo<br>
    Private EffSummary As Object<br>
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load<br>
<br>
    End Sub<br>
    Sub AddTransactionRow()<br>
<br>
        'actually rows aadded using datatable , any way user can edit both Item_qty & Item_Price<br>
        GVTransactions.RowCount = GVTransactions.RowCount + 1<br>
        GVTransactions.Rows(GVTransactions.RowCount - 1).Cells("Transaction_id").Value = GVTransactions.RowCount<br>
        GVTransactions.Rows(GVTransactions.RowCount - 1).Cells("Item_code").Value = 11511 & GVTransactions.RowCount<br>
        GVTransactions.Rows(GVTransactions.RowCount - 1).Cells("Item_name").Value = "product" & GVTransactions.RowCount<br>
<br>
        GVTransactions.Rows(GVTransactions.RowCount - 1).Cells("Item_qty").Value = 500<br>
        GVTransactions.Rows(GVTransactions.RowCount - 1).Cells("Item_Price").Value = 10<br>
        GVTransactions.Rows(GVTransactions.RowCount - 1).Cells("total").Value = GVTransactions.Rows(GVTransactions.RowCount - 1).Cells("Item_qty").Value _<br>
            * GVTransactions.Rows(GVTransactions.RowCount - 1).Cells("Item_Price").Value<br>
<br>
    End Sub<br>
<br>
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click<br>
        AddTransactionRow()<br>
        SummaryRows()<br>
<br>
    End Sub<br>
    Sub SummaryRows()<br>
<br>
        Dim summaryRowItem As New GridViewSummaryRowItem()<br>
<br>
        Dim summaryItemTotal As New GridViewSummaryItem()<br>
        summaryItemTotal.Name = "Total"<br>
        summaryItemTotal.Aggregate = GridAggregateFunction.Sum<br>
        summaryRowItem.Add(summaryItemTotal)<br>
<br>
<br>
        Dim summaryItemeffectsTotal As New GridViewSummaryItem()<br>
        summaryItemeffectsTotal.Name = "Effects_net"<br>
        summaryItemeffectsTotal.Aggregate = GridAggregateFunction.Sum<br>
        summaryRowItem.Add(summaryItemeffectsTotal)<br>
<br>
        Dim summaryItemnet As New GridViewSummaryItem()<br>
        summaryItemnet.Name = "Net_After_Effects"<br>
        summaryItemnet.Aggregate = GridAggregateFunction.Sum<br>
        summaryRowItem.Add(summaryItemnet)<br>
        GVTransactions.SummaryRowsBottom.Clear()<br>
<br>
        GVTransactions.SummaryRowsBottom.Add(summaryRowItem)<br>
<br>
        GVTransactions.SummaryRowsBottom(0)(0).FormatString = "{0:f2}"<br>
        GVTransactions.SummaryRowsBottom(0)(1).FormatString = "{0:f2}"<br>
        GVTransactions.SummaryRowsBottom(0)(2).FormatString = "{0:f2}"<br>
<br>
<br>
    End Sub<br>
<br>
    Private Sub GVTransactions_Click(sender As Object, e As EventArgs) Handles GVTransactions.Click<br>
<br>
    End Sub<br>
<br>
    Private Sub GVTransactions_CommandCellClick(sender As Object, e As EventArgs) Handles GVTransactions.CommandCellClick<br>
<br>
        If EffTemplloaded = False Then<br>
            colEffInPer = New GridViewDecimalColumn<br>
            EffValue = New GridViewDecimalColumn<br>
            EffLstCol = New GridViewTextBoxColumn<br>
<br>
            TmpEff = New GridViewTemplate<br>
<br>
<br>
            EffLstCol.Name = "Eff_name"<br>
<br>
<br>
            EffLstCol.Width = 400<br>
            EffLstCol.HeaderText = "Effect Name"<br>
            colEffInPer.HeaderText = "Effect Percent"<br>
            EffValue.HeaderText = "Value"<br>
<br>
            TmpEff.Columns.Add(EffLstCol)<br>
            TmpEff.Columns.Add("Transaction_id")<br>
            colEffInPer.Name = "eff_Percent"<br>
            EffValue.Name = "ColEffValue"<br>
            EffValue.FormatString = "{0:f2}"<br>
<br>
            EffValue.ReadOnly = True<br>
            TmpEff.Columns.Add(colEffInPer)<br>
<br>
            TmpEff.Columns.Add(EffValue)<br>
<br>
<br>
            TmpEff.Columns("Transaction_id").IsVisible = False<br>
<br>
            TmpEff.AllowAddNewRow = False<br>
            GVTransactions.MasterTemplate.Templates.Add(TmpEff)<br>
<br>
            Effrelation = New GridViewRelation(GVTransactions.MasterTemplate)<br>
            Effrelation.ChildTemplate = TmpEff<br>
            Effrelation.RelationName = "r1"<br>
            Effrelation.ParentColumnNames.Add("Transaction_id")<br>
            Effrelation.ChildColumnNames.Add("Transaction_id")<br>
            GVTransactions.Relations.Add(Effrelation)<br>
            EffTemplloaded = True<br>
<br>
            Dim summaryItem As New GridViewSummaryItem()<br>
<br>
            summaryItem.Name = "ColEffValue"<br>
            summaryItem.Aggregate = GridAggregateFunction.Sum<br>
<br>
            Dim summaryRowItem As New GridViewSummaryRowItem()<br>
            summaryRowItem.Add(summaryItem)<br>
<br>
            TmpEff.SummaryRowsBottom.Add(summaryRowItem)<br>
<br>
<br>
        End If<br>
<br>
        Dim EffRow As GridViewDataRowInfo<br>
<br>
        EffRow = GVTransactions.MasterTemplate.Templates(0).Rows.AddNew<br>
        EffRow.Cells("Transaction_id").Value = GVTransactions.SelectedRows(0).Cells("Transaction_id").Value<br>
<br>
<br>
        GVTransactions.MasterTemplate.ExpandAll()<br>
<br>
<br>
    End Sub<br>
    Private Sub GVTransactions_CellValueChanged(sender As Object, e As GridViewCellEventArgs) Handles GVTransactions.CellValueChanged<br>
<br>
        If e.Column.Name = "eff_Percent" Then<br>
<br>
<br>
            TmpEff.Rows(e.RowIndex).Cells("ColEffValue").Value = e.Row.ViewInfo.ParentRow.Cells("total").Value * (TmpEff.Rows(e.RowIndex).Cells("eff_Percent").Value / 100)<br>
<br>
            e.Row.ViewInfo.ParentRow.Cells("Effects_net").Value = e.Row.ViewInfo.ParentRow.Cells("Effects_net").Value + TmpEff.Rows(e.RowIndex).Cells("ColEffValue").Value<br>
            e.Row.ViewInfo.ParentRow.Cells("Net_After_Effects").Value = e.Row.ViewInfo.ParentRow.Cells("total").Value - e.Row.ViewInfo.ParentRow.Cells("Effects_Net").Value<br>
        End If<br>
<br>
        GVTransactions.EndEdit()<br>
    End Sub<br>
End Class


5- simply Do as next steps to get my point

1-click on Add item button.
2-click on cell button to add new effect.
3-enter any number to effect percent cell and then press enter.

simply in this event or (any thing you suggest) i want to see summary of effects value column in net effects in parent row , and recalculate all summaries in grid.
 
thank you very much

best regards




0
George
Telerik team
answered on 22 Oct 2013, 07:42 AM
Hello Mohammad,

Thank you for writing back.

In this case it is enough to subscribe to the CellValueChanged event of the grid and change the value of the corresponding cell. It will update the summary data:
Private Sub GVTransactions_CellValueChanged(sender As Object, e As GridViewCellEventArgs)
    If e.Column.Name = "eff_Percent" Then
        Me.GVTransactions.Rows(0).Cells("Effects_net").Value = e.Value.ToString()
    End If
End Sub

I also suggest you to take a look at our articles about managing hierarchical data in RadGridView - http://www.telerik.com/help/winforms/gridview-hierarchical-grid-binding-to-hierarchical-data.html

I hope this helps.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Mohammad
Top achievements
Rank 1
Answers by
George
Telerik team
Mohammad
Top achievements
Rank 1
Share this question
or