Windows Forms Topics include: windows forms, controls, components and designers

Go Back  Xtreme .NET Talk > .NET > Windows Forms > Datagrid Running Total Column


Reply
 
Thread Tools Display Modes
  #1  
Old 04-02-2004, 11:53 AM
Roey's Avatar
Roey Roey is offline
Junior Contributor
 
Join Date: Oct 2002
Location: Canada
Posts: 238
Roey is on a distinguished road
Post Datagrid Running Total Column



I am looking to create a column in my datagrid that does a running total of items eg

Item Qty Running Total

Part 1....4...........4
Part 2....6..........10
Part 3....7..........17

Not sure if I should be computing on a new dataset column or using SQL


Thanks in advance
Reply With Quote
  #2  
Old 04-04-2004, 03:28 AM
Joe Mamma's Avatar
Joe Mamma Joe Mamma is offline
Senior Contributor

Preferred language:
C#,Delphi
 
Join Date: Mar 2004
Location: Washington DC
Posts: 1,062
Joe Mamma is on a distinguished road
Post

Quote:
Originally Posted by Roey
I am looking to create a column in my datagrid that does a running total of items eg

Item Qty Running Total

Part 1....4...........4
Part 2....6..........10
Part 3....7..........17

Not sure if I should be computing on a new dataset column or using SQL


Thanks in advance
I cant think of anyway to do that in SQL, but not hard in a dataset column. . .

something along the lines of this

value column = n
total column = t
curr row = r

for i = 0 to rows.count-1 do
if (r = 0)
rows[r]col[t] = rows[r]col[n]
else
rows[r]col[t] = rows[r-1]col[n] + rows[r]col[n]
__________________
Joe Mamma
Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.
Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Reply With Quote
  #3  
Old 04-04-2004, 10:23 PM
Roey's Avatar
Roey Roey is offline
Junior Contributor
 
Join Date: Oct 2002
Location: Canada
Posts: 238
Roey is on a distinguished road
Default

I ended up doing it like this
Code:
Dim i As Integer

For i = 0 To Me.dsInventory.Tables("TransActions").Rows.Count - 1
    If i = 0 Then
         Me.dsInventory.Tables("TransActions").Rows(i)("Extended") = Me.dsInventory.Tables("TransActions").Rows(i)("Quantity")
    Else
         Me.dsInventory.Tables("TransActions").Rows(i)("Extended") = CType(Me.dsInventory.Tables("TransActions").Rows(i)("Quantity"), Decimal) + CType(Me.dsInventory.Tables("TransActions").Rows(i - 1)("Extended"), Decimal)
    End If
Next i
Any comments or suggestions would be welcomed. Thanks
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the total number of items in a datagrid esposito ASP.NET 1 07-29-2004 12:28 PM
Creating a variable from a datagrid total Jackpanel ASP.NET 1 06-08-2004 12:35 PM
Keeping a Running Total Mwagner5600 General 6 03-07-2004 01:26 PM
crystal report - running total field ashrobo Database / XML / Reporting 11 06-10-2003 08:37 PM

Advertisement:







Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe