Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Im searching for a solution but i can't find any answer, Please Help me...

i have 2 cells that i want to compute and display the total.. the below code is actually fine and compute only single row, my problem is i need to compute every row automatically when i press the button2...

VB
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

     For i As Integer = 0 To DataGridView2.RowCount - 1
         Dim xQty As Double = CDbl(DataGridView2.Rows(i).Cells(8).Value)
         Dim xPrc As Double = CDbl(DataGridView2.Rows(i).Cells(9).Value)
         DataGridView2.Rows(i).Cells(10).Value = xQty * xPrc
     Next

 End Sub

for example:

Product--------Price--------Quantity--------Total Amount
Apple----------10.00-----------2---------------20
Banana---------20.00-----------3---------------20
Orange---------10.00------------5---------------30

the first row, apple automatically change the total amount when i change the price and click the button..
but the second and third row nothing happened. i need to compute every row in just one click... thanks in advanced
Posted
Updated 20-Oct-14 21:34pm
v3
Comments
There is a loop. Isn't it working?
[no name] 21-Oct-14 0:25am    
You are using web or windows ?
TheHellGirl 29-Oct-14 1:11am    
Im using windows
Richard MacCutchan 21-Oct-14 3:36am    
Use your debugger to step through the code and see why the loop is not repeating.
Sinisa Hajnal 21-Oct-14 4:25am    
Why not use cellvalidated, cellvaluechanged or any other cell event to calculate the total value directly on change?

See if Computed Columns[^]

or Cell events [^]

help you.

If you really need on button update, try calling Datagridview2.Refresh and/or Invalidate after the loop finishes.
 
Share this answer
 
Comments
TheHellGirl 29-Oct-14 1:49am    
Thanks for the Help :)
Howdy All,
Try this after the for loop:

Dim cm As CurrencyManager = DirectCast(datqaGridView2.BindingContext(dataGridView2.DataSource), _ CurrencyManager)
cm.Refresh()


regs,

ron O.
 
Share this answer
 
Comments
TheHellGirl 29-Oct-14 1:50am    
Thanks for the Help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900