Programming for Everybody: Visual Basic.net: how to calculate third column in a datagridview as product of two other columns

Visual Basic.net: how to calculate third column in a datagridview as product of two other columns

 

Public Class Form8

    Private Sub Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim table As New DataTable("table")

        table.Columns.Add("ID", Type.GetType("System.Int32"))

        table.Columns.Add("Name", Type.GetType("System.String"))

        table.Columns.Add("Arabic", Type.GetType("System.Double"))

        table.Columns.Add("English", Type.GetType("System.Double"))

        table.Columns.Add("Sum", Type.GetType("System.Double"))

       DataGridView1.DataSource = table

    End Sub

    Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit

        For i As Integer = 0 To DataGridView1.Rows.Count - 1

            Dim a1 As Double = DataGridView1.Rows(i).Cells(2).Value

            Dim b1 As Double = DataGridView1.Rows(i).Cells(3).Value

            Dim c1 As Double = a1 + b1

            DataGridView1.Rows(i).Cells(4).Value = c1

        Next

    End Sub

    Private Sub DataGridView1_DefaultValuesNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles DataGridView1.DefaultValuesNeeded

        e.Row.Cells("Arabic").Value = "0"

        e.Row.Cells("English").Value = "0"

        e.Row.Cells("Sum").Value = "0"

    End Sub



No comments:

Post a Comment