Click here to Skip to main content
12,894,200 members (71,144 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
How to Sum total amount in DataGridView
Column1	Column2	Column3	Column n	 TOTAL
500	100	300	900
200	75	100	375
100	25	150	275
400	50	225	675
500	100	450	1050

Please tell me how to sum total.
Posted 19-Feb-13 8:10am
Updated 19-Feb-13 8:15am
Maciej Los 19-Feb-13 14:19pm
and the data comes from???
Navas Khanj 19-Feb-13 14:22pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you can get the data from table, use this:
SELECT Column1, Column2, Column3, ColumnN, (Column1 + Column2 + Column3 + ColumnN) AS TOTAL
FROM TableName

Do not forget to use COALESCE()[^] function. Why? Read it.
Sergey Alexandrovich Kryukov 19-Feb-13 18:40pm
It might not be the correct question, just because OP only answered "table", without any detail, so who knows what is that?
Nevertheless, I voted 5, because all of the above is not so important. What is important, is the idea to have some data layers and work with this data layer, without using a broken telephone of the UI.
Messing with UI messes up isolation between layers and makes project non-maintainable.
Sergey Alexandrovich Kryukov 19-Feb-13 18:42pm
In view of that, I decide to elaborate. Please see Solution 2.
Maciej Los 20-Feb-13 12:33pm
Thank you, Sergey ;)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Please see the Solution 1, taking into account my comment to it. You were moving in wrong direction.

I suggest you learn and analyze applicability of the following architectural patterns ([^]):

MVVM — Model View View Model,[^],

MVC — Model-View-Controller,[^]),

MVA — Model-View-Adapter,–view–adapter[^],

MVP — Model-View-Presenter,[^].

Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

Maciej Los 20-Feb-13 12:33pm
Good suggestion, my 5!
Sergey Alexandrovich Kryukov 20-Feb-13 14:10pm
Thank you, Maciej.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100