We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Detect duplicate records

Thread ID:

Created:

Updated:

Platform:

Replies:

130327 May 6,2017 10:07 PM UTC May 8,2017 01:15 PM UTC Windows Forms 1
loading
Tags: GridGroupingControl
Josip Pejakovic
Asked On May 6, 2017 10:07 PM UTC

Hello!

How to properly detect duplicate input in grid?

I'm doing that on this way:

private void gridSirovina_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e)
if (e.Action == CurrentRecordAction.EndEditCalled)
            {
                Record rec = e.Record as Record;
                string myCode = Convert.ToString(rec.GetValue("SifraRobe"));

foreach (Record r in e.Table.Records)
                        {                         
                            string existValue = r.GetValue(gridSirovina.TableDescriptor.Fields["SifraRobe"]).ToString();
                            if (myCode == existValue)
                            {
                                MessageBox.Show("Exists!");
                                e.Cancel = true;
                                break;
                            }
                        }
}
}

But this works fine only in case when inserting new records. When changing existing record I get error that value exist even it is different than others in that specific cell. Is there any other way to efficient way to check duplicates?

Mohanraj Gunasekaran [Syncfusion]
Replied On May 8, 2017 01:15 PM UTC

Hi Josip,  
 
Thanks for using Syncfusion products.  
 
 We have analyzed your provided code part. In your code part, you have tried to check the duplicate value by iterating through records collection . If you edit the cell value, the record value has updated in RecordsCollection so the MessageBox(“Exists”) appears even if it has a different value. In order to overcome this scenario, you can use the RowIndex property in CurrentRecordContextChange event. Please refer to the below code example,  
  
Code example,  
   
this.gridGroupingControl1.CurrentRecordContextChange += gridGroupingControl1_CurrentRecordContextChange;  
  
void gridGroupingControl1_CurrentRecordContextChange(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e)  
{  
    if (e.Action == Syncfusion.Grouping.CurrentRecordAction.EndEditCalled)  
    {  
        Record rec = e.Record as Record;  
        int newIndex = rec.GetRowIndex();  
        string myCode = Convert.ToString(rec.GetValue("Country"));  
        if (this.gridGroupingControl1.Table.CurrentRecord != null )  
        {  
            foreach (Record r in e.Table.Records)  
            {  
                int rowindex = r.GetRowIndex();  
                string existValue = r.GetValue(this.gridGroupingControl1.TableDescriptor.Fields["Country"]).ToString();  
                if (myCode == existValue && rowindex != newIndex)  
                {  
                    MessageBox.Show("Exists!");  
                    e.Cancel = true;  
                    break;  
                }  
            }  
        }  
    }  
}  
 
Sample link: GridGroupingCotnrol  
 
Regards,  
Mohanraj G  
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;