Click here to Skip to main content
12,360,522 members (62,156 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
v3
Comments
Maciej Los 19-Feb-13 14:19pm
   
and the data comes from???
Navas Khanj 19-Feb-13 14:22pm
   
Table
Rate this: bad
 
good
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.
  Permalink  
Comments
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.
—SA
Maciej Los 20-Feb-13 12:33pm
   
Thank you, Sergey ;)
Sergey Alexandrovich Kryukov 19-Feb-13 18:42pm
   
In view of that, I decide to elaborate. Please see Solution 2.
—SA
Rate this: bad
 
good
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 (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):


MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].


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

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

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.160621.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2016
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