问题描述
如果我有7行和27列的数据网格视图,如果我需要将单元格的值与其他单元格进行比较怎么做?
详情:
我需要将第1行单元格值与6行单元格值的其余部分进行比较,对于第2行,对于其余5行重复相同的事情,同样需要对第3行进行相同的比较,其余为4行。基本上是行比较
ROW1-> 2 2 2 4 4 6 6 8 8 8 7 7
ROW2-> 1 1 1 7 7 7 6 9 9 9 7 7
ROW3-> 1 1 3 3 3 3 5 5 5 0 0 0
ROW4-> 2 2 2 0 0 0 0 1 1 1 7 7
ROW5-> 0 0 0 3 3 3 4 4 4 8 8 8
现在我想为那些值重复的Cell着色。任何想法对我都有很大的帮助。
If I have a datagridview of say 7 Rows and 27 Columns and if I need to compare the values of cells with another cells how to do it?
Detail:
I need to compare 1st Row cell value with rest of the 6 rows cell values, same thing repeats for 2nd Row for rest 5 row, again same comparison needed for 3rd row with rest 4 rows. Basically It is row wise comparison
ROW1-> 2 2 2 4 4 6 6 8 8 8 7 7
ROW2-> 1 1 1 7 7 7 6 9 9 9 7 7
ROW3-> 1 1 3 3 3 3 5 5 5 0 0 0
ROW4-> 2 2 2 0 0 0 0 1 1 1 7 7
ROW5-> 0 0 0 3 3 3 4 4 4 8 8 8
Now I want to color those Cell whose values are repeating. Any idea will be a great help for me.
推荐答案
for(int comparerRow = 0; comparerRow < rowCount - 1; comparerRow++)
{
for(int compareeRow = comparerRow + 1; compareeRow < rowCount; compareeRow++)
{
for(int columnIndex = 0; columnIndex < columnCount; columnIndex++)
{
// Comparison and visual effect
}
}
}
重要的标准杆t是内部行循环必须依赖于外部行循环的迭代变量。所以它不会一次又一次地从头开始。
The important part is that the inner row loop has to depend on the outer row loop's iteration variable. So it won't start from the beginning over and over again.
这篇关于如何比较datagridview的单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!