在Winform中,我用dataGridView的CurrentCellChanged事件绑定显示当前活动行的数据同步到对应的TextBox里,但是当在TextBox里输入数据进行插入或者修改行时,dataGridView不能同步更新显示。我想重新对dataGridView进行填充,但是在CurrentCellChanged里报错说没实例化。请问应该如何更新让DataGridView同步显示啊?

解决方案 »

  1.   

    string text2 = this.textBox2.Text.Trim();
    string text3 = "http://" + this.textBox3.Text.Trim();
    string text4 = this.textBox4.Text.Trim();
    string text5 = this.textBox5.Text.Trim();
    string text6 = System.DateTime.Now.ToString();
    string sendValues = "('" + text2 + "','" + text3 + "','" + text4 + "','" + text5 + "','" +text6 + "')";
    string sendSQL = "insert 网址管理 (标题,网址,用户名,密码,更新时间) values " + sendValues;
    this.link.UpdateDataBase(sendSQL);
    MessageBox.Show("数据保存成功!", "信息");
    //我用这行代码重新填充datagridview就报错。
    this.网址管理TableAdapter.Fill(this.myDbDataSet.网址管理);
      

  2.   

    在你重新填充数据的时候,触发了CurrentCellChanged事件,
    但是没有填充完成,就没办法得到对象,于是抱错,建议:
    或者自己手动生成DataSoursce,改东西就改你自己那个DataSource,然后异步让数据库更新
      

  3.   

    可以在你Fill的时候,把CurrentCell设置为null
      

  4.   

    如何把CurrentCell设置成null啊?