A calculated field in an updatable gridview in a winforms application

Posted on 2010-01-05
Last Modified: 2013-11-07
I have a gridview with three columns. The first two columns contain numbers. I want the third column to be the sum of the two preceding columns. So, if a user enters, or modifies, a value in one of the first two columns, the third column is recalculated.
Question by:Frans_Truyens
    LVL 13

    Accepted Solution

    You should then add a oncellchanged event and do your calculation and update the 3rd column

    Author Comment

    Can you give an example? I don't find the Cell changed event of my gridview.

    Author Comment

    This is my code. I would like to fill column 5 with the sum of column4 and column3.
            adp = New OleDb.OleDbDataAdapter(strSQL, GetConnection)
            dsSchenking = New DataSet
            adp.Fill(dsSchenking, "Schenking")
            Me.gridSchenking.DataSource = dsSchenking.Tables("Schenking")
            Me.gridSchenking.Columns("HistoriekDetID").Visible = False
            Dim colTest1 As New DataGridViewComboBoxColumn
            colTest1.Items.Add(GetVertaling("In volle eigendom", pstrTaal))
            colTest1.Items.Add(GetVertaling("In blote eigendom", pstrTaal))
            colTest1.Items.Add(GetVertaling("Met voorbehoud van vruchtgebruik", pstrTaal))
            colTest1.DataPropertyName = "TypeSchenking"
            colTest1.HeaderText = "Type schenking"
            colTest1.Width = 200
            colTest1.DisplayIndex = 0
            Dim colTest2 As DataGridViewColumn
            colTest2 = Me.gridSchenking.Columns(1)
            colTest2.Width = 150
            Dim colTest3 As DataGridViewColumn
            colTest3 = Me.gridSchenking.Columns(2)
            colTest3.Width = 100
            Dim colTest4 As DataGridViewColumn
            colTest4 = Me.gridSchenking.Columns(3)
            colTest4.Width = 100
            Dim colTest5 As DataGridViewColumn
            colTest5 = Me.gridSchenking.Columns(4)
            colTest5.Width = 100
            Dim colTest6 As DataGridViewColumn
            colTest6 = Me.gridSchenking.Columns(5)
            colTest6.Width = 100

    Open in new window


    Author Comment

    Could anyone help me?

    Author Closing Comment

    This solved my problem. Thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now