Click here to Skip to main content
11,504,892 members (68,233 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: 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
Edited 19-Feb-13 8:15am
Maciej Los at 19-Feb-13 14:19pm
and the data comes from???
Navas Khanj at 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 at 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.
Maciej Los at 20-Feb-13 12:33pm
Thank you, Sergey ;)
Sergey Alexandrovich Kryukov at 19-Feb-13 18:42pm
In view of that, I decide to elaborate. Please see Solution 2.
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 at 20-Feb-13 12:33pm
Good suggestion, my 5!
Sergey Alexandrovich Kryukov at 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
0 F-ES Sitecore 285
1 CHill60 245
2 Sergey Alexandrovich Kryukov 213
3 OriginalGriff 185
4 Richard Deeming 180
0 Sergey Alexandrovich Kryukov 723
1 Peter Leow 490
2 Maciej Los 475
3 DamithSL 470
4 OriginalGriff 437

Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2015
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