Why doesn't qty column increment when adding in textbox to datagridview in vb.net.
so the qty column can only max the value to 2 is there something wrong with my code should continue to grow if the product code is the same as the product column in the DataGridView.
Thanks
Private Sub BindItemDetail()
If _myTable.Rows.Count = 0 Then
Dim field() As String = {"No", "Codeproduct", "Barcode", "Qty"}
_myTable = DataControl.CreateDataTableDynamic(field)
End If
grid.DataSource = _myTable
End Sub
Private Sub FillDataTable(iRow As Integer, ByVal Codeproduct As String, ByVal Barcode As String, ByVal Qty As Integer, ByVal Coledit As String, ByVal ColDel As String)
Dim row As DataRow = _myTable.NewRow()
row("No") = iRow
row("Codeproduct") = Codeproduct
row("Barcode") = Barcode
row("Qty") = Qty
_myTable.Rows.Add(row)
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
Dim iRow As Integer
If Grid.RowCount - 1 = 0 Then
iRow = 1
Else
iRow = Convert.ToInt32(Grid.Rows(Grid.RowCount - 2).Cells(0).Value.ToString()) + 1
End If
Dim Qty As Integer = 1
Dim Found As Boolean = False
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
For j = 0 To Me.Grid.Rows.Count - 1
If Convert.ToString(Me.Grid.Rows(j).Cells(1).Value) = TextBox1.Text.ToString() Then
Found = True
'The problem in my code is in below the code line
Grid.Rows(j).Cells(3).Value = Qty + 1
TextBox1.Clear()
TextBox2.Clear()
Exit For
End If
Next
If Not Found Then
FillDataTable(iRow, TextBox1.Text, TextBox2.Text, Qty)
Grid.DataSource = _myTable
TextBox1.Clear()
TextBox2.Clear()
End If
End If
End Sub
Desired result
No | CodeProduct | Barcode | Qty |
---|---|---|---|
1 | 1000 | 1000 | 3 |
2 | 1002 | 1002 | 1 |