2016-03-28 13 views
-2

でDataGridViewの列の合計値見つけ、私が見つけ、データグリッドビューの列の検索のidの数量値を合計するvb.net

Textbox1は一つだけを示し、問題がされていることを、このコード

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 
を使用しています上で検索された行の値。例えば

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

Textbox1のみ4.

答えて

1

とすぐに最初の値をヒットとして結果を示し、次の文のために終了します。したがって、あなたは決して最初の価値を渡すことはありません。 Exitを消すと機能するはずです。

+0

彼はまた_after_ループまで 'TextBox1.Text'を設定して待たなければなりません。 –

0

もしDataGridView2.RowCount> 1その後 薄暗いtqtyとして整数= 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 
関連する問題