Combine 2 rows and find duplicates

Hi I have my data residing inside sfdatagrid as shown below,


UniqueId          HostId             Id

                         123               256
                         123               324
                         256               123
                         489               456
                         123               256
                         489               456

how can I merge the HostId and Id and stored in UniqueId row so I will be expecting in my DataRow

UniqueId          HostId             Id

123256             123               256
123324             123               324
256123             256               123
489456             489               456
123256             123               256
489456             489               456

after getting this duplicated in my sfdatagrid, If possible to highlight each duplicate?

say for example 123256 and 489456 color = red?

1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team June 7, 2021 11:32 AM UTC

Hi Mark Jayvee,

Thank you for contacting Syncfusion support.

Your requirement can be achieved by using DataColumn in DataTable and Customize the QueryCellStyle event in SfDataGrid. Please refer the below code snippet, 
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; 
                        } 
                    } 
                } 
         } 
} 
For more information related to QueryCellStyle event, please refer the below user guide documentation,

UG Link: https://help.syncfusion.com/windowsforms/datagrid/conditionalstyling#styling-based-on-content

Please let us know if you have any concerns in this. 

Regards, 
Vijayarasan S 


Marked as answer
Loader.
Up arrow icon