this is the below code in which when user press enter then the details of textbox go into gridview then again when user press enter then if that record is already available then not allow to insert in gridview.i a unable to do this please help any one...

If Asc(e.KeyChar) = 13 Then
            If txt_itemno.Text = "" And txt_qty.Text = "" And txt_disc.Text = "" Then

            ElseIf txt_qty.Text > qty Then
                MsgBox("Insufficient qty.")
                txt_qty.Focus()
            Else
                Dim intcount As Integer = 0
                For Each Row As DataGridViewRow In dgv_sale.Rows
                    If dgv_sale.Rows(intcount).Cells(0).Value = Val(txt_itemno.Text) Then
                        res = MsgBox("Item Already Exist.Do You Want To Replace It", MsgBoxStyle.YesNo)
                        If res = 6 Then
                            i = intcount
                            chk = 1
                        ElseIf res = 7 Then

                        End If
                        intcount += 1
                    Else
                        chk = 0
                    End If
                Next Row

                If chk = 1 Then
                    dgv_sale.Rows.RemoveAt(i)
                    dgv_sale.Rows.Insert(i, dgv_sale.Rows.Add(txt_itemno.Text, txt_prodname.Text, txt_qty.Text, txt_price.Text, txt_disc.Text, txt_netamt.Text))
                    dis = dis + Val(txt_disc.Text)
                    amt = amt + Val(txt_netamt.Text)
                    txt_dis.Text = dis
                    txt_amt.Text = amt
                    txt_prodname.Text = ""
                    txt_qty.Text = ""
                    txt_price.Text = ""
                    txt_disc.Text = ""
                    txt_netamt.Text = ""
                ElseIf chk = 0 Then
                    dgv_sale.Rows.Add(txt_itemno.Text, txt_prodname.Text, txt_qty.Text, txt_price.Text, txt_disc.Text, txt_netamt.Text)
                    txt_itemno.Text = ""
                    txt_prodname.Text = ""
                    txt_qty.Text = ""
                    txt_price.Text = ""
                    txt_disc.Text = ""
                    txt_netamt.Text = ""
                End If
            End If
        End If

You could loop through the values and check if they are equal:

For i As Integer = 0 To dataGridView1.Rows.Count - 1
    For j As Integer = 0 To dataGridView1.Columns.Count - 1
        If IsNothing(dataGridView1.Rows(i).Cells(j).Value) = False And YourStringValueHere = dataGridView1.Rows(i).Cells(j).Value.ToString() Then

            'Item found

            Exit For
        End If
    Next
Next

hey bigginerdev i just want to check row so should i use column loop too...?

hey bigginerdev i am getting nullexception handler error

Where is the null exception being thrown?

I am assuming it is from the "YourStringValueHere"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.