|
-
Oct 5th, 2004, 08:55 AM
#1
Thread Starter
Fanatic Member
datagrid total
I have a datagrid which is bound to a filtered dataview, what is the best way to go about totalling the numerical values and putting them in the footer
VB Code:
Dim dr As DataRowView
Dim range01tot As Decimal = 0.0
Dim i As IEnumerator = dvOne.GetEnumerator()
While (i.MoveNext())
dr = i.Current
range01tot += (dr("value"))
End While
Last edited by davebat; Oct 6th, 2004 at 07:24 AM.
-
Oct 5th, 2004, 12:13 PM
#2
Hyperactive Member
Re: datagrid total
Originally posted by davebat
I have a datagrid which is bound to a filtered dataview, what is the best way to go about totalling the numerical values and putting them in the footer
I tried two methods:
1) use SQL to compute SUM;
2) use a loop and fetch the values for each row in the datagrid, then add them;
do not know whether they are good methods, but both work for me.
-
Oct 5th, 2004, 12:19 PM
#3
Fanatic Member
It's in C# but you should get the idea.
Code:
DataRowView dr; int hoursCount=0;
IEnumerator i=viewStaffSchedule.GetEnumerator();
while(i.MoveNext())
{
dr=(DataRowView)i.Current;
hoursCount+=int.Parse(dr["ProjectHours"].ToString());
}
lblTotalHours.Text=hoursCount.ToString();
-
Oct 6th, 2004, 02:41 AM
#4
Thread Starter
Fanatic Member
thanks both of you, Brian I have translated this as well as i can into VB and am just unsure about the int.parse part, Im still pretty new to this.
VB Code:
Dim dr As DataRowView
Dim rangeo1tot As Integer = 0
Dim i As IEnumerator = dvOne.GetEnumerator()
While (i.MoveNext())
dr = i.Current
range01tot += Int.Parse(dr, "range01".ToString())
End While
The int is underlined as an error "Overload resolution failed because no accesible 'int' accepts this number of arguments" Do you know what i need to do
-
Oct 6th, 2004, 03:02 AM
#5
Hyperactive Member
try to use the:
VB Code:
range01tot += Integer.Parse(dr, "range01".ToString())
-
Oct 6th, 2004, 03:35 AM
#6
Thread Starter
Fanatic Member
it needed to be
VB Code:
range01tot += Integer.Parse(dr("range01").ToString())
I found a good c# to vb converter at
http://authors.aspalliance.com/aldot...translate.aspx
Only problem now is that I get the error message "Input string was not in a correct format. "
-
Oct 6th, 2004, 07:06 AM
#7
Thread Starter
Fanatic Member
-
Oct 6th, 2004, 09:10 AM
#8
Fanatic Member
This line maybe?
Code:
dr=(DataRowView)i.Current;
I noticed yours doesn't have it. It's casting the enumerator to a DataRowView - I think the VB equivalent is CType.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|