Add Sum of cells from Data Table column to a new column on the same row.

I have a Data Table with two or three weight and cube columns on each row. What I need to do is get a total for each into a weight total and cube total column. Can anyone tell me how to get this done ?

DGV.DataSource = dataTable;
GD_GRAYAsked:
Who is Participating?

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

x
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.

it_saigeDeveloperCommented:
You can accomplish this with DataColumn expressions:
using System.Data;
using System.Windows.Forms;

namespace EE_Q28690908
{
	public partial class Form1 : Form
	{
		private DataTable table = new DataTable();

		public Form1()
		{
			InitializeComponent();
			table = GetTable();
			dataGridView1.DataSource = table;
		}

		private DataTable GetTable()
		{
			DataTable table = new DataTable();
			table.Columns.Add("Type", typeof(string));
			table.Columns.Add("Weight1", typeof(int));
			table.Columns.Add("Weight2", typeof(int));
			table.Columns.Add("Cube1", typeof(int));
			table.Columns.Add("Cube2", typeof(int));
			table.Columns.Add("WeightTotal", typeof(int), "Weight1 + Weight2");
			table.Columns.Add("CubeTotal", typeof(int), "Cube1 + Cube2");

			table.Rows.Add("Order", 250, 15, 25, 3);
			table.Rows.Add("Order", 1000, 300, 100, 15);
			return table;
		}
	}
}

Open in new window

Which produces the following output -Capture.JPG
You could also use events to calculate the columns.

-saige-

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
GD_GRAYAuthor Commented:
LoL, Thank you !   I jacked around with this for hours and you did it in what.....  no time...
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
.NET Programming

From novice to tech pro — start learning today.