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. Image for the cookie policy date

How to find duplicates in grid

Hi,
I try to find a way, to format cells in gridcontrol to become red if there is duplicate values.
In excel conditional formatting I do:
=CountIf(A:A, A1)>1

It means check entire column A for occurences of value in Cell A1 and count them. if count > 1 then set cell background color in i.e. red.And then I copy this formula in all the cells in current column.

Please help.


1 Reply

AD Administrator Syncfusion Team February 28, 2008 06:52 PM UTC

Hi Luka,

Thank you for your interest in Syncfusion products.

You can achieve this task using GridFindReplaceDialog class, instead of using the formula. Please refer the code below for more details.

GridFindReplaceDialogSink fr;
private void buttonAdv1_Click(object sender, EventArgs e)
{
string SearchedText = string.Empty;
GridFindReplaceEventArgs fre;
GridFindReplaceDialog frDialog = GridFindReplaceDialog.Instance;
GridFindTextOptions options = GridFindTextOptions.MatchCase | GridFindTextOptions.MatchWholeCell;
object locInfo = GridRangeInfo.Table();
int rowIndex, colIndex;


fr = new GridFindReplaceDialogSink(this.gridControl1);

frDialog.SetState(this.fr, "", false);
frDialog.TopMost = false;
frDialog.TextSearched = SearchedText;
frDialog.TextSearched = "ABC";

GridCurrentCell cc = this.gridControl1.CurrentCell;
this.gridControl1.Model.Selections.Add(GridRangeInfo.Cell(cc.RowIndex, cc.ColIndex));
GridRangeInfo selRange = GridRangeInfo.Cells(1, 1, gridControl1.RowCount, gridControl1.ColCount);
int startTop = selRange.Top;
int startLeft = selRange.Left;
while (GridFindReplaceDialogSink.GetNextCell(selRange, ref startTop, ref startLeft, false, false))
{
GridStyleInfo style = gridControl1[startTop, startLeft];
GridCellRendererBase renderer = gridControl1.CellRenderers[style.CellType];
if (renderer.FindText(this.gridControl1[1, 1].Text, startTop, startLeft, options, true))
{
gridControl1.CurrentCell.GetCurrentCell(out rowIndex, out colIndex);
gridControl1[rowIndex, colIndex].BackColor = Color.Orange;
}
}
}

Please refer the code below that implements this task.
http://websamples.syncfusion.com/samples/Grid.Windows/F72008/main.htm

Note:
When you click "Select Duplication of First Cell' button in the attached sample, then it will highlight the duplicate value of the first cell.

Please let me know if this helps.

Regards,
Srirajan



Loader.
Live Chat Icon For mobile
Up arrow icon