|
var table = this.GetDataTable();
DataColumn portStatus = new DataColumn();
portStatus.DataType = typeof(int);
portStatus.ColumnName = "UniqueId";
//combine the values by using expression
portStatus.Expression= "Id+ '' +HostId";
table.Columns.Add(portStatus);
sfDataGrid1.DataSource = table;
sfDataGrid1.QueryCellStyle += SfDataGrid1_QueryCellStyle;
private void SfDataGrid1_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e)
{
//check the column based on MappingName
if (e.Column.MappingName == "UniqueId")
{
bool isExist= false;
//check dupicate values in SfDataGrid
for (int i = 0; i < sfDataGrid1.View.Records.Count; i++)
{
//skip the current row
if ((e.RowIndex - 1) != i)
{
//check value exist or not
isExist = (sfDataGrid1.View.Records[i].Data as DataRowView).Row[e.ColumnIndex].ToString() == e.DisplayText;
if (isExist)
{
//Highlight the duplicate cell
e.Style.BackColor = Color.Red;
break;
}
}
}
}
} |