Articles in this section
Category / Section

How to enter the unique value in WinForms DataGrid (SfDataGrid)?

1 min read

In SfDataGrid you can make a specific column accept unique value per row using SfDataGrid.CurrentCellValidating event.

sfDataGrid1.CurrentCellValidating += SfDataGrid1_CurrentCellValidating;private void SfDataGrid1_CurrentCellValidating(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellValidatingEventArgs e)
{
    if (e.Column.MappingName == "OrderID")
    {
        for (int i = 0; i < sfDataGrid1.View.Records.Count; i++)
        {
            if ((this.sfDataGrid1.View.Records[i].Data as OrderInfo).OrderID.ToString().Equals((e.NewValue.ToString()))&&(e.NewValue.ToString() != e.OldValue.ToString()))
            {
                e.IsValid = false;
                e.ErrorMessage = "Invalid Value";
                break;
            }
        }
    }
}

Demo to show the column allows unique values per row

View Sample in GitHub.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied