Hi,
I need to highlight duplicates in a grid. I am using CellFormatting to validate data, probably should do it somewhere else?. The grid is unbound.
How do I find the duplicate and change the appearance of it? This seems to be a rather bad way to do this.
| private void mygrid_CellFormatting(object sender, CellFormattingEventArgs e) | |
| { | |
| if (e.CellElement.ColumnInfo is GridViewDataColumn && !(e.CellElement.RowElement is GridTableHeaderRowElement)) | |
| { | |
| if (e.CellElement.ColumnIndex == userEmailColumn.Index) | |
| { | |
| string emailValue = e.CellElement.RowInfo.Cells[userEmailColumn.Index].Value as string; | |
| if (!String.IsNullOrEmpty(emailValue)) | |
| { | |
| Match match = emailRegexValidation.Match(emailValue); | |
| if (!((match.Success && (match.Index == 0)) && (match.Length == emailValue.Length))) | |
| { | |
| e.CellElement.ForeColor = Color.Red; | |
| e.CellElement.ToolTipText = "E-mail is invalid"; | |
| valid = false; | |
| } | |
| // now look if there are any duplicates and mark them all | |
| // Loop through all cells and find the duplicates? |
Thanks,
/ jorge