Reputation: 147
I am hoping somebody can help me out here and that this questions won't be too vague.
I am trying to determine a way that I can highlight the differences between two text strings within a winform.
I have the original string in one column of a data grid and the string to compare to in a second column. What I would like is to highlight where the comparison string is different within the data grid view itself.
Example:
Thanks for the hep
Thanks for the help!!
where the l
, and two !
would be highlighted
I have tried the following (Shout out to Bouam for his help in this Previous Post):
for (int i = 0; i < TextProcessingResults.RowCount; i++)
{
if (TextProcessingResults.Rows[i].Cells[1].Value != null)
{
if ((string)TextProcessingResults.Rows[i].Cells[1].Value != (string)TextProcessingResults.Rows[i].Cells[2].Value)
{
TextProcessingResults.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
}
}
}
But this only highlights which rows are different not at the character level. I'm new to all of this, so is this a crazy endeavor to undertake?
Could anybody help or point me towards a resource that would be useful?
Upvotes: 2
Views: 392
Reputation: 125277
You can create a new DatGridViewColumn
based on RichTextBox
and then use your new rich text column, to highlight differences in rich text.
This may help you:
And here is an ouptput based on this:
You can apply the algorithm you need to compare strings for differences to columns and using this DataGridViewRichTextBoxColumn
highlight the differences.
To learn more about creating custom datagridview column types you can take a look at Build a Custom NumericUpDown Cell and Column for the DataGridView Control.
Upvotes: 2