for (int n = 1; n < dataGridView1.Columns.Count; n++)
            {
                if (dataGridView.Rows[0].Cells[6].Value == dataGridView1.Rows[0].Cells[n].Value)
                {
                    MessageBox.Show(Convert.ToString(n));
                }
            }这段代码该如何修改?

解决方案 »

  1.   


     for (int n = 0; n < dataGridView1.Columns.Count-1; n++)
                {
                    if (dataGridView.Rows[0].Cells[6].Value == dataGridView1.Rows[0].Cells[n].Value)
                    {
                        MessageBox.Show(Convert.ToString(n));
                    }
                }
      

  2.   

    在n=3时 两值相等
    但是还是不执行MessageBox.Show(Convert.ToString(n));
      

  3.   

    if (dataGridView.Rows[0].Cells[6].Value.ToString() == dataGridView1.Rows[0].Cells[n].Value.ToString())
                    {
                        MessageBox.Show(Convert.ToString(n));
                    }
      

  4.   

    for (int n = 0; n < dataGridView1.Columns.Count-1; n++)
                {
                    if (dataGridView.Rows[0].Cells[6].Value.ToString() == dataGridView1.Rows[0].Cells[n].Value.ToString())                {
                        MessageBox.Show(Convert.ToString(n));
                    }
                }