Create Invoice in RadGridview

1 Answer 180 Views
GridView
Nandan
Top achievements
Rank 1
Iron
Iron
Iron
Nandan asked on 15 Feb 2022, 01:45 PM

Hi

I want to create sales invoice in radgridview. when user start entry in item name which is combobox in radgridview which data (item name and qty) will come from item master user enter qty total should be calculated automatically at the same time grand total should shown radgridview footer.

when user press save button all entries in radgridview should save database. I need after which event footer will be updated. or if i remove radgridview row radgridview footer should be updated.

 

Regards

Nandan Navale

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Feb 2022, 02:27 PM
Hello, Nandan,    

RadGridView offers calculated columns identified by an expression. Thus, you can specify how the value to be calculated by this column. More information is available here:
https://docs.telerik.com/devtools/winforms/controls/gridview/columns/calculated-columns-(column-expressions

You can use summary rows to show summary information about the displayed data, such as first item, last item, count, total sum, etc. The summary rows can be top and bottom pinned:
https://docs.telerik.com/devtools/winforms/controls/gridview/rows/summary-rows 

As to the question about saving the changes to the database, you can use the following approach:
https://docs.telerik.com/devtools/winforms/controls/gridview/populating-with-data/updating-the-database-with-ado.net   

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Nandan
Top achievements
Rank 1
Iron
Iron
Iron
commented on 16 Feb 2022, 06:05 AM | edited

Hi Dess

Thanks for your reply. I want to ask like asp.net gridview can we add command button at end of radgridview to delete particular row. I am able to  calculate column like qty * rate total.  This is for horizontal i want to display total gross total to footer so which event i have to use so footer gross total will be change accordingly row inserted or deleted 

 

 

Thanks & Regards

 

Nandan Navale

Dess | Tech Support Engineer, Principal
Telerik team
commented on 16 Feb 2022, 12:13 PM

Hi, Nandan,

RadGridView offers command columns as well. More information how to use it is available in the following article:

https://docs.telerik.com/devtools/winforms/controls/gridview/columns/column-types/gridviewcommandcolumn 

As to the "footer" with calculations, note that the summary rows automatically recalculate the value when a row is deleted or added.

Nandan
Top achievements
Rank 1
Iron
Iron
Iron
commented on 16 Feb 2022, 01:47 PM

Hi Dess

Thank you for your Help..

From given tutorials from you i have idea how to do it. But one question is pending that how to get grand total on summary row. I mean after which event summary row will be updated. Kindly check screen shot so you will understand.

i put qty and rate total automatically get calculated but summary rows is not updated.

regards

Nandan Navale

 

 

Dess | Tech Support Engineer, Principal
Telerik team
commented on 18 Feb 2022, 11:35 AM

Hi, Nandan,

The summary rows update automatically their value whenever a new row is added, an existing one is updated or deleted. I have prepared a sample code snippet for your reference:

            GridViewDecimalColumn qty = new GridViewDecimalColumn("Qty");
            this.radGridView1.Columns.Add(qty);
            GridViewDecimalColumn rate = new GridViewDecimalColumn("Rate");
            this.radGridView1.Columns.Add(rate);

            GridViewDecimalColumn col = new GridViewDecimalColumn("Total"); 
            radGridView1.Columns.Add(col);
            radGridView1.Columns["Total"].Expression = "Qty * Rate";
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            this.radGridView1.Rows.Add(10, 20);

            GridViewSummaryItem summaryItem = new GridViewSummaryItem();
            summaryItem.Name = "Total";
            summaryItem.Aggregate = GridAggregateFunction.Sum;
            GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
            summaryRowItem.Add(summaryItem); 
            this.radGridView1.SummaryRowsBottom.Add(summaryRowItem);

Please refer to the below achieved result: 

Nandan
Top achievements
Rank 1
Iron
Iron
Iron
commented on 18 Feb 2022, 03:51 PM

Hi Dess

Thanks for reply. With your help i have written code in radgridview.  Kindly check its working.

Public Class frmtest
    Dim dbManager As New SqlHelper(ConfigurationManager.ConnectionStrings("ConString").ToString())
    Private Sub frmtest_Load(sender As Object, e As EventArgs) Handles Me.Load
        SetupGridViewForTransaction()
    End Sub
    Private Sub SetupGridViewForTransaction()

        ObjGrdView.AutoGenerateColumns = False

        ObjGrdView.Columns.Clear()

        Dim ColtSrNo As New GridViewTextBoxColumn()
        ColtSrNo.Name = "ColtSrNo"
        ColtSrNo.HeaderText = "Sr.No"
        ColtSrNo.TextAlignment = ContentAlignment.BottomRight
        ColtSrNo.Width = 25
        ObjGrdView.MasterTemplate.Columns.Add(ColtSrNo)

        Dim ColItemName As GridViewComboBoxColumn = New GridViewComboBoxColumn("ColItemName")
        ColItemName.HeaderText = "Item"
        ColItemName.DataSource = FetchAllRecords()
        ColItemName.FieldName = "ItemName"
        ColItemName.ValueMember = "ItemId"
        ColItemName.DisplayMember = "ItemName"
        ColItemName.Width = 100
        Me.ObjGrdView.Columns.Add(ColItemName)

        Dim ColQty As GridViewDecimalColumn = New GridViewDecimalColumn("ColQty")
        ColQty.HeaderText = "Qty"
        ColQty.DecimalPlaces = 3
        Me.ObjGrdView.Columns.Add(ColQty)

        Dim ColRate As GridViewDecimalColumn = New GridViewDecimalColumn("ColRate")
        ColRate.HeaderText = "Rate"
        ColRate.DecimalPlaces = 3
        Me.ObjGrdView.Columns.Add(ColRate)

        Dim ColTotal As GridViewDecimalColumn = New GridViewDecimalColumn("ColTotal")
        ColTotal.HeaderText = "Total"
        ColTotal.DecimalPlaces = 3
        ColTotal.FormatString = "{0:N2}"
        Me.ObjGrdView.Columns.Add(ColTotal)

        ObjGrdView.Columns("ColTotal").Expression = "ColQty * ColRate"
        Me.ObjGrdView.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill

        Dim colFooterTotal As GridViewSummaryItem = New GridViewSummaryItem("ColRate", "Total", GridAggregateFunction.Count)

        Dim summaryItem As GridViewSummaryItem = New GridViewSummaryItem()
        summaryItem.Name = "ColTotal"
        summaryItem.Aggregate = GridAggregateFunction.Sum

        Dim summaryRowItem As GridViewSummaryRowItem = New GridViewSummaryRowItem(New GridViewSummaryItem() {})
        summaryRowItem.Add(summaryItem)

        Dim totalRow As GridViewSummaryRowItem = New GridViewSummaryRowItem(New GridViewSummaryItem() {colFooterTotal, summaryItem})
        Me.ObjGrdView.SummaryRowsBottom.Add(totalRow)

        AddHandler ObjGrdView.CommandCellClick, AddressOf ObjGrdView_CommandCellClick
    End Sub
    Private Function FetchAllRecords() As DataTable

        Dim dtData As DataTable = New DataTable()

        Try
            Dim parameters = New List(Of SqlParameter)()
            parameters.Clear()

            With parameters
                .Add(dbManager.CreateParameter("@ActionType", "FillOnlyItemName", DbType.String))
            End With

            dtData = dbManager.GetDataTable("SP_ItemMaster_Select", CommandType.StoredProcedure, parameters.ToArray())

        Catch ex As Exception
            MessageBox.Show("Error:- " & ex.Message)
        End Try

        Return dtData

    End Function
    Private Sub ObjGrdView_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles ObjGrdView.CellFormatting
        If e.CellElement.ColumnInfo.Name = "ColtSrNo" Then
            e.CellElement.Text = (e.CellElement.RowIndex + 1).ToString()
        End If
    End Sub
    Private Sub ObjGrdView_RowValidating(sender As Object, e As RowValidatingEventArgs) Handles ObjGrdView.RowValidating
        e.Row.ErrorText = String.Empty
        If TypeOf e.Row Is GridViewDataRowInfo Then
            If e.Row.Cells(4).Value Is Nothing OrElse String.IsNullOrEmpty(e.Row.Cells(4).Value.ToString()) Then
                e.Row.ErrorText = "Empty value is not allowed"
                e.Cancel = True
            End If
        End If
    End Sub
    Private Sub ObjGrdView_CommandCellClick(sender As Object, e As GridViewCellEventArgs) Handles ObjGrdView.CommandCellClick
        Me.ObjGrdView.Rows.RemoveAt(0)
    End Sub
    Private Sub ObjGrdView_CellValidating(sender As Object, e As CellValidatingEventArgs) Handles ObjGrdView.CellValidating
        'Dim column As GridViewDataColumn = TryCast(e.Column, GridViewDataColumn)
        'If TypeOf e.Row Is GridViewDataRowInfo AndAlso column IsNot Nothing AndAlso column.Name = "ColQty" Then
        '    If String.IsNullOrEmpty(DirectCast(e.Value, String)) OrElse DirectCast(e.Value, String).Trim() = String.Empty Then
        '        e.Cancel = True
        '        DirectCast(e.Row, GridViewDataRowInfo).ErrorText = "Validation error!"
        '    Else
        '        DirectCast(e.Row, GridViewDataRowInfo).ErrorText = String.Empty
        '    End If
        'End If
    End Sub
    Private Sub ObjGrdView_ViewCellFormatting(sender As Object, e As CellFormattingEventArgs) Handles ObjGrdView.ViewCellFormatting
        If TypeOf e.Row Is GridViewSummaryRowInfo Then
            If e.Column.Name = "ColRate" Then
                e.CellElement.TextAlignment = ContentAlignment.MiddleCenter
            Else
                e.CellElement.TextAlignment = ContentAlignment.MiddleRight
            End If
        End If

        If TypeOf e.CellElement Is GridSummaryCellElement Then
            Dim summaryFont As Font = New Font("Tahoma", 9, FontStyle.Bold)
            e.CellElement.Font = summaryFont
        End If
    End Sub
End Class

need suggestion if any

Question is closed. thanks again

Regards

Nandan Navale


 

 

 

Nandan
Top achievements
Rank 1
Iron
Iron
Iron
commented on 20 Feb 2022, 02:23 PM | edited

Hi dess

I have write code to fill radgrdiview. When user select number for dropdownlist then radgridview will be populated using datatable. it works correctly but grand total is not coming at summaryrow level.

kindly go through my code

Private Sub SetupGridView()

        ObjGrdView.AutoGenerateColumns = False
        ObjGrdView.EnableFiltering = False
        ObjGrdView.MasterTemplate.ShowHeaderCellButtons = True
        ObjGrdView.MasterTemplate.ShowFilteringRow = False
        ObjGrdView.CurrentRow = Nothing
        ObjGrdView.Columns.Clear()

        Dim ColtSrNo As GridViewTextBoxColumn = New GridViewTextBoxColumn("ColtSrNo")
        ColtSrNo.HeaderText = "Sr.No"
        ColtSrNo.TextAlignment = ContentAlignment.BottomRight
        ColtSrNo.Width = 25
        ObjGrdView.MasterTemplate.Columns.Add(ColtSrNo)

        Dim ColItemType As GridViewTextBoxColumn = New GridViewTextBoxColumn("ColItemType")
        ColItemType.HeaderText = "Item Type"
        ColItemType.FieldName = "ItemType"
        ColItemType.TextAlignment = ContentAlignment.MiddleLeft
        ColItemType.Width = 25
        Me.ObjGrdView.Columns.Add(ColItemType)

        Dim ColLotNo As GridViewTextBoxColumn = New GridViewTextBoxColumn("ColLotNo")
        ColLotNo.HeaderText = "Slip/Bag No"
        ColLotNo.FieldName = "SlipBagNo"
        Me.ObjGrdView.Columns.Add(ColLotNo)

        Dim ColItemName As GridViewTextBoxColumn = New GridViewTextBoxColumn("ColItemName")
        ColItemName.HeaderText = "ItemName"
        ColItemName.FieldName = "ItemName"
        Me.ObjGrdView.Columns.Add(ColItemName)

        Dim ColGrossWt As GridViewDecimalColumn = New GridViewDecimalColumn("ColGrossWt")
        ColGrossWt.HeaderText = "Gross Wt."
        ColGrossWt.FieldName = "GrossWt"
        ColGrossWt.DecimalPlaces = 2
        Me.ObjGrdView.Columns.Add(ColGrossWt)

        Dim ColGrossPr As GridViewDecimalColumn = New GridViewDecimalColumn("ColGrossPr")
        ColGrossPr.HeaderText = "Gross %"
        ColGrossPr.FieldName = "GrossPr"
        ColGrossPr.DecimalPlaces = 2
        ColGrossPr.FormatString = "{0:N2}"
        Me.ObjGrdView.Columns.Add(ColGrossPr)

        Dim ColFineWt As GridViewDecimalColumn = New GridViewDecimalColumn("ColFineTotal")
        ColFineWt.HeaderText = "Fine Total"
        ColFineWt.FieldName = "FineWt"
        ColFineWt.DecimalPlaces = 3
        ColFineWt.FormatString = "{0:N2}"
        Me.ObjGrdView.Columns.Add(ColFineWt)

        Dim totalNameItem As GridViewSummaryItem = New GridViewSummaryItem("ColItemName", "Total", GridAggregateFunction.Count)
        Dim totalItemGWt As GridViewSummaryItem = New GridViewSummaryItem("ColGrossWt", "{0}", GridAggregateFunction.Sum)
        Dim totalItemGFt As GridViewSummaryItem = New GridViewSummaryItem("ColFineWt", "{0}", GridAggregateFunction.Sum)

        Dim totalItemGPr As GridViewSummaryItem = New GridViewSummaryItem("ColGrossPr", "{0: 0.00}", GridAggregateFunction.None)
        totalItemGPr.AggregateExpression = "(Sum(colFineWt) / Sum(ColGrossWt)  * 100)"

        Dim totalRow As GridViewSummaryRowItem = New GridViewSummaryRowItem(New GridViewSummaryItem() {totalNameItem, totalItemGWt, totalItemGFt, totalItemGPr})
        Me.ObjGrdView.SummaryRowsBottom.Add(totalRow)

    End Sub

 

Private Sub cmbLotNo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbLotNo.SelectedIndexChanged
        Dim dtData As DataTable = New DataTable()

        If cmbLotNo.SelectedIndex > 0 Then
            Dim parameters = New List(Of SqlParameter)()
            parameters.Clear()

            With parameters
                .Add(dbManager.CreateParameter("@ActionType", "FetchMeltingReport", DbType.String))
                .Add(dbManager.CreateParameter("@MId", cmbLotNo.SelectedValue, DbType.Int16))
            End With

            dtData = dbManager.GetDataTable("SP_Melting_Select", CommandType.StoredProcedure, parameters.ToArray())

            If dtData.Rows.Count > 0 Then
                Me.SetupGridView()
                ObjGrdView.DataSource = dtData
            Else

            End If

        End If
    End Sub

Regards

Nandan Navale

 

 

Hristo
Telerik team
commented on 23 Feb 2022, 09:28 AM

Hi Nandan,

If I correctly understand your current setup, you would need to update the summary row. You can achieve this by invalidating it this way: 

this.radGridView1.MasterView.SummaryRows[0].InvalidateRow();

Please note that I am not able to directly test your code as it depends on your database. If you would like us to look into your exact scenario, you can open up a support ticket and send us a runnable sample project so that we can investigate it in details.

Regards,

Hristo

Nandan
Top achievements
Rank 1
Iron
Iron
Iron
commented on 24 Feb 2022, 01:35 PM

Hi Hristo

Thanks for your reply,  Unfortunately your solutions does not work or I dont know how to use this. In this form if i change index of tabcontrol summary row increase row by row. You can see in screen shot.

 Private Sub dgvNTLSampleReport_CellValueChanged(sender As Object, e As GridViewCellEventArgs) Handles dgvNTLSampleReport.CellValueChanged
        If e.Column.Name = "colSampleWt" Then
            Me.dgvNTLSampleReport.MasterView.SummaryRows(0).InvalidateRow()
        End If
    End Sub

Regards

Nandan Navale

 

 

 

Dess | Tech Support Engineer, Principal
Telerik team
commented on 28 Feb 2022, 01:51 PM

Hello, Nandan,

Without replicating the issue locally, it wouldn't be easy to determine what causes this undesired behavior on your end. That is why I would highly encourage you to submit a support ticket from your Telerik account and provide a sample runnable project demonstrating the problem you are facing. Thus, we would be able to make an adequate analysis of the precise case and provide further assistance. The following tutorial gives some useful tips and tricks when submitting support tickets: 
https://docs.telerik.com/devtools/winforms/knowledge-base/submit-support-tickets 

I hope this information helps. 
Tags
GridView
Asked by
Nandan
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or