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.

How to find duplicates in grid

Thread ID:

Created:

Updated:

Platform:

Replies:

72008 Feb 26,2008 10:52 AM Feb 28,2008 01:52 PM Windows Forms 1
loading
Tags: GridControl
Luka
Asked On February 26, 2008 10:52 AM

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.


Administrator [Syncfusion]
Replied On February 28, 2008 01:52 PM

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



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.

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.

;