2016-03-28 9 views
-2

bir DataGridView sütununun toplamı değeri bul ve ben bulup veri ızgara görünümünde sütununda aranır id qty değerini özetlemek istiyorum vb.net

Textbox1 tek gösteren sorun olduğunu bu kodu

Dim tqty As Double 
For Each row As DataGridViewRow In dgv.Rows 
    If row.Cells.Item(0).Value = cmbItemCode.Text Then 
     tqty += row.Cells.Item(4).Value 
     Textbox1.text=tqty 
     Exit For 
    End If 
Next 
kullanıyorum en çok aranan satır değeri. Örneğin

id  item name qty 
1  abc   4 
2  xyz   10 
1  abc   10 

Textbox1 sadece 4.

cevap

1

hemen sonra ilk değer vurmak olarak Sonucu gösterir, for ifadesi çıkın. Bu yüzden asla ilk değeri geçemezsiniz. Exit'i silmek için çalışması gerekir.

+0

O da _after_ döngü kadar 'TextBox1.Text' ayarı ile beklemelidir. –

0

Eğer DataGridView2.RowCount> 1 Sonra Dim tqty olarak Integer = 0

 'if you have the other column to get the result you could add a new one like these above 
     For index As Integer = 0 To DataGridView2.RowCount - 1 
      amount += Convert.ToInt32(DataGridView2.Rows(index).Cells(2).Value) 

      'if you have the other column to get the result you could add a new one like these above (just change Cells(2) to the one you added) 
     Next 
     TextBox1.Text = tqty 
İlgili konular