【问题标题】:Compare cells of two rows of a datagrid view highlighing the ones that dont match比较 datagridview 的两行的单元格,突出显示不匹配的单元格
【发布时间】:2018-06-21 19:39:05
【问题描述】:

这就是我所拥有的。从同一张表的两个不同数据库中获取数据的查询。给每个 row_number() 和 Location 以及我需要评估的所有相关列的数据。所以我有两行,第一列为 1,第一列的第二列是 Home,第二行第二列是远程的。然后是所有要比较的列。根据所比较的表格,最多可能只有 5 个相关列(最多 31 个)。 因此,我的 C# 代码填充了 DGV,然后我开始遍历每个 col 2,第 1 行比较 col 2 第 2 行,如果不相等,则使每个单元格变为红色。 然后下一个 col col3 第 1 行,Col3 第 2 行一直到行对的 col 列表。 它在 40 行对和 10 列上还不错,但我有一些 4800 行对和 30 列的实例。 有没有人有更快的方法然后逐个单元格。我有想过接受我的 slq 查询并设置一些标志?在我的智慧尽头。

【问题讨论】:

    标签: c# sql datagridview


    【解决方案1】:

    这工作得非常快。 注意:我不排除 row_number() 列,进行 NULL 检查等...

     private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
            {
                if ((e.RowIndex > 0) && (e.ColumnIndex > 0) && ((e.RowIndex % 2) == 0))
                {
                    if (!dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.Equals(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value))
                    {
                        e.Graphics.FillRectangle(Brushes.Red, e.CellBounds);
                        e.PaintContent(e.CellBounds);
                        e.Handled = true;
                    }
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-26
      相关资源
      最近更新 更多