Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi friends
I new to using datagridview.I am trying to make a data entry form using an unbound dgv in which I have added columns and row using code but I have difficulty on how to calculate between columns.
I can do it if I add the columns in design time .I would like to know if it is possible to add expression column or calculates between two columns when i add columns and rows like this.

VB
Dim dt As New DataTable
        dt.Columns.Add("col1")
        dt.Columns.Add("col2")
        dt.Columns.Add("col3")
        dt.Columns.Add("col4")
        dt.Columns.Add("total")

        dt.Rows.Add("")
        dt.Rows.Add("")
        dt.Rows.Add("")
        dt.Rows.Add("")

        Me.DataGridView1.DataSource = dt
        dt.Columns("total").Expression = "[col2]+[col3]"
Posted

1 solution

VB
Try this

        Dim dt As New DataTable
        dt.Columns.Add("col1")
        dt.Columns.Add("col2")
        dt.Columns.Add("col3")
        dt.Columns.Add("col4")
        dt.Columns.Add("total")

        dt.Rows.Add("")
        dt.Rows.Add("")
        dt.Rows.Add("")
        dt.Rows.Add("")
 dt.Columns("total").Expression = "[col2]+[col3]"
 Me.DataGridView1.DataSource = dt
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900