for (int i = 0; i < this .dataGridView1 .Rows .Count ;i++ )
     {            
                if (this.textBox.Text != this.dataGridView1.Rows[i].Cells[0].Value.ToString ())
                {
                    
                }
     }
这样写不知道为什么出错,提示说 《未将对象引用设置到对象的实例。。》
请问该怎么解决呢?谢谢!

解决方案 »

  1.   

    string.IsNullOrEmpty(this.textBox.Text )判断
    Equals(this.dataGridView1.Rows[i].Cells[0].Value.ToString())
      

  2.   

    看看你的allowuseraddrow属性是否为true,若是该为false
      

  3.   

    或者不改alluseraddrow,把代码
    for (int i = 0; i < this .dataGridView1 .Rows .Count ;i++ )
    改成
    for (int i = 0; i < this .dataGridView1 .Rows .Count - 1 ;i++ )
    也行
      

  4.   

    for (int i = 0; i < this.dataGridView1.Rows.Count - 1; i++)
                {
                      if (Equals(this.dataGridView1.Rows[i].Cells[0].Value.ToString().Trim(), this.textBox.Text.ToString().Trim()) == false)
                    {
                        ------------
                    }
                }