Vb.net datagridview Column


I`d like to add a column named "C" to my datagridview which will be the sum of each row in columns "A" and "B",

Like this :

column A  Column B   Column C
2                 5                  7

How would I add this column to my datagridview?

Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
You surely have a datatable behind your datagid? add a calculated column to your datatable as shown in https://msdn.microsoft.com/en-us/library/vstudio/zwxk25bd(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
FCapoAuthor Commented:
I'm importing the data from excel into a dataset :

     Dim MyConnection As System.Data.OleDb.OleDbConnection
        Dim DtSet As System.Data.DataSet
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
        MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='S:\Cms\EnviroMap.xls';Extended Properties=Excel 12.0 Xml")
        MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [enviroMap$]", MyConnection)
        MyCommand.TableMappings.Add("Table", "Net-informations.com")
        DtSet = New System.Data.DataSet
        DataGridView1.DataSource = DtSet.Tables(0)

Open in new window

Éric MoreauSenior .Net ConsultantCommented:
So you have a datatable:

DtSet.Tables(0).Columns.Add("SalesTax", Type.GetType("System.Double"),   "A + B)
DataGridView1.DataSource = DtSet.Tables(0)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.