• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

Vb.net datagridview Column

Hi,

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
0
FCapo
Asked:
FCapo
  • 2
1 Solution
 
É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
0
 
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
        MyCommand.Fill(DtSet)
        DataGridView1.DataSource = DtSet.Tables(0)
        MyConnection.Close()

Open in new window

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

MyCommand.Fill(DtSet)
DtSet.Tables(0).Columns.Add("SalesTax", Type.GetType("System.Double"),   "A + B)
DataGridView1.DataSource = DtSet.Tables(0)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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