[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

A calculated field in an updatable gridview in a winforms application

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.
0
Frans_Truyens
Asked:
Frans_Truyens
  • 4
1 Solution
 
zadeveloperCommented:
You should then add a oncellchanged event and do your calculation and update the 3rd column
0
 
Frans_TruyensAuthor Commented:
Can you give an example? I don't find the Cell changed event of my gridview.
0
 
Frans_TruyensAuthor Commented:
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
        Me.gridSchenking.Columns.Remove("TypeSchenking")
        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
        Me.gridSchenking.Columns.Add(colTest1)
        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

0
 
Frans_TruyensAuthor Commented:
Could anyone help me?
0
 
Frans_TruyensAuthor Commented:
This solved my problem. Thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now