I’v some query about my code. Im a beginner in VB2005, I js want to add some item n my dgCart(DataGrid) from my txtISBNInfo & txtTitleInfo (Textbox). Upon addin it, the itemx must be limited into 3, and the dgCart(DataGrid) should not contain any doubling or duplication ov items. What should I do?
In my for each it will to determine if it exists and then only after it has determined it doesn’t exist, add a new row. By that I mean… Here I show you my code but regrettably it doesn’t work…
Private Sub btnAddToCart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddToCart.Click
Dim IsFound As Boolean = False
Dim Count As Integer = dgCart.Rows.Count
For Each dgvRow As DataGridViewRow In dgCart.Rows
If dgvRow.Cells("clmISBN").Value.ToString = txtISBNInfo.Text Then
IsFound = True
'at this point you can actually exit for because you have the info you need.
End If
Next
If IsFound Then
dgCart.Rows.Add(txtISBNInfo.Text, txtTitleInfo.Text)
Else
MsgBox("Already in list!")
End If
End Sub
I think you pretty much had it but you had the
ifstatement at the end swapped