日期:2014-05-17  浏览次数:20749 次

代码很简单,但是就是不知道出错的原因在哪里!囧~
功能:遍历datagridview控件中“关键词”所在列的值,如果存在相同的值,则将重复的值标记为空!
代码如下
int k,m;
            for(k=0;k<dataGridView.RowCount;++k)
            {
                for (m = 1; m<dataGridView.RowCount;++m )
                {
                    if ((m>k)&&(dataGridView.Rows[k].Cells["keyword"].Value == dataGridView.Rows[m].Cells["keyword"].Value))
                    {
                        dataGridView.Rows[m].Cells["keyword"].Value = null;
                    }
                }
            }

程序的结果是,点击按钮,没有任何的反映,求教各位高手如何解决!

DataGridView 控件 遍历

------解决方案--------------------
for(int k=0;k<dataGridView.RowCount;k++)
            {
                for (int m = k+1; m<dataGridView.RowCount;m++ )
                {
                    if ((dataGridView.Rows[k].Cells[0].Text == dataGridView.Rows[m].Cells[0].Text))
                    {