Help with datagrid column

sunnyjulka

Member
Joined
Sep 12, 2005
Messages
17
Programming Experience
1-3
Hello everyone
I have a datagrid which shows selected rows from my Inventory table. One of the columns in the datagrid shows the price of the item. How can I add the price column for the whole datagrid and display that in a label.
Thanks in advance
 
You will use your source data for that. Is it a DataView? If you are showing selected rows from a table, you should probably be using a DataView as your source for the DataGrid. Then, you could just cycle through the rows in the DataView and add up the values in that column.

Example:
VB.NET:
'dtInventory is the DataTable
dim PriceTotal as Double
dim dv as DataView = new DataView(dtInventory)
dv.Filter = "some filter" 'Apply your filter
myDataGrid.DataSource = dv
for i as integer = 0 to dv.Count - 1
PriceTotal += dv(i)("Price")
next
lblPrice.Text = PriceTotal.ToString
 
Last edited:
Like this:

VB.NET:
For i as Int64 = 0 to dsInventory.Tables("MyTableName").Rows.Count - 1
    PriceTotal += dsInventory.Tables("MyTableName").Rows(i)("price")
Next
 
Back
Top