Hi, i have this datagridview containing column: {product, price, quantity, Total price}, and a 'calculate' button. I need to enter the quantity column and when I press 'calculate' button, it will calculate total price by price*quantity
what i am struggling now is how to grab the 'text' in "quantity" column, as i won't fill everything in it, maybe only one row.

Example:

product price quantity total price
-------------------------------------------------
topaz 100
emerald 400 4
gold 300 2


How to get the text in quantity? --> "4" and "2"
and i want to multiply it with the "price"

thanks!

Recommended Answers

All 4 Replies

humm.. its easy.. if you want just the total price in Total price column..

do something like this

Dim i As Integer
        For i = 0 To Me.DataGridView1.Rows.Count - 2
            Me.DataGridView1.Rows(i).Cells(3).Value = Double.Parse(Me.DataGridView1.Rows(i).Cells(1).Value) * Double.Parse(Me.DataGridView1.Rows(i).Cells(2).Value)
        Next

here : Me.DataGridView1.Rows(i).Cells(1).Value = price
Me.DataGridView1.Rows(i).Cells(2).Value = quantity

i see

that really helps.

But i wonder in the loop, why it is Count - 2?
I think it should be Count - 1 right?

How to work in Linq to Sql ion asp.net c#

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.