简体   繁体   中英

Highlight differences between strings on winform

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?

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 atBuild a Custom NumericUpDown Cell and Column for the DataGridView Control .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM