Get all data from a column in a datagridview

Hi..

How do I get all data from a column in a datagridview
I want to calulate the total amount in one column
LVL 1
AWestEngAsked:
Who is Participating?
 
DhaestCommented:
Do you want to show data from a database into a datagrid ?
http://www.awprofessional.com/articles/article.asp?p=446453
0
 
planoczCommented:
HI AWestEng,
Check this link it has colunm totals
http://www.timvw.be/developing-a-datasource-for-your-datagridview/
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
You can ...

Dim total As Integer
For x As Integer = 0 To (MyDataGridView.Rows.Count-1)
   total = total + CType(MyDataGridView.Rows(x).Cells(YourColumnIndex).Value, Integer)
Next x
Debug.Print(total)
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Jorge PaulinoIT Pro/DeveloperCommented:
I think that AWestEng just wants the total in a variable!
0
 
vbturboCommented:
Hi,

you can use the DataColumn.Expression Property which also provide aggregation and sum's collumns

http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx

if you're working with DataTables, you can perform aggregate function over its rows. For example, table.Compute("sum(price)", "") would calculate the sum on all rows over price column in your DataTable.

as shown here

dim myvalue as Object
myvalue = dsSale.Tables("Grid").Compute("Sum(columnToBeCalulated)", "")

should give the total(sum of all rows) in that column.


vbturbo
0
 
AWestEngAuthor Commented:
thx guys.. :)
0
 
AWestEngAuthor Commented:
ops I was to fast vbturbo:, did not see you message sorry.
0
 
vbturboCommented:
No problem

Just glad you solved it -:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.