How to check duplicate particular value in radgridview in vb.net winforms

1 Answer 161 Views
Forum suggestions
Nandan
Top achievements
Rank 1
Iron
Iron
Iron
Nandan asked on 07 Aug 2023, 08:31 AM

Hi

 

I am using raddatagridviews in vb.net. I want to check if particular item should  not be enter in raddatagridview.  So far I have done this but not working

  Private Sub ChkDuplicateItem()
        Dim Found As Boolean = False

        For i = 0 To Me.dgvCore.Rows.Count - 1
            If Convert.ToString(Me.dgvCore.Rows(i).Cells(3).Value.ToString.Contains("Core")) = txtItemName.Text.Trim() Then
                Found = True
                Exit For
            End If
        Next

        'Return Found

        If Not Found Then
            Me.fillGrid()
        End If
    End Sub

SrNoItemidItemNameQtyRateAmount
110KDM51050
210KDM1010100
320Core254100
420Core15375
This  Core Item should not repeat again

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Aug 2023, 01:10 PM

Hi, Nandan,

RadGridView offers a convenient API for data validation while editing. The UserAddingRow event allows you to validate the entered data in the new row and prevent the new row from being committed as a data row by setting the GridViewRowCancelEventArgs.Cancel property to true:

https://docs.telerik.com/devtools/winforms/controls/gridview/rows/new-row#user-events

The CellValidating event allows you to validate the cell values separately so that you can check for duplicate values and cancel the editor's value: 

https://docs.telerik.com/devtools/winforms/controls/gridview/editors/data-validation 

As to the process of checking for duplicates, it is necessary to iterate all the rows and see whether the editor's value exists in any of the cells from the respective column. Thus, you will determine whether the new value is unique or a duplicate already exists. Please give it a try and see how it works on your end.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Forum suggestions
Asked by
Nandan
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or