数据放到datagridview
// 相同数值出现的次数
int j=0;
for (int i = 0; i<dataGridView1.Rows.Count - 1; i++)
{
int qyg = int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
int hyg = int.Parse(dataGridView1.Rows[i + 1].Cells[2].Value.ToString());
j++;
//前后列数据比较
不同则改变值
if (qyg != hyg)
{
for (int k = 0; k < j; k++)
{
if (k == 0)
dataGridView1.Rows[i - k].Cells[2].Value = 3;
else if (k == j - 1)
dataGridView1.Rows[i - k].Cells[2].Value = 1;
else
dataGridView1.Rows[i - k].Cells[2].Value = 2;
}
j = 0;
}
// 最后一个列没得比较 特殊处理
if (i == dataGridView1.Rows.Count - 2)
{
dataGridView1.Rows[i +1].Cells[2].Value = 3;
for (int k = 0; k < j; k++)
{
if (k == j - 1)
dataGridView1.Rows[i - k].Cells[2].Value = 1;
else
dataGridView1.Rows[i - k].Cells[2].Value = 2;
}
j = 0;
}
}
新手 请指点