按代码更改Text属性

时间:2013-06-18 09:42:04

标签: c# sql

我有一个DataSource连接到几个带有BindingSource的文本框。在textBox中键入值时,BindingSource会将新值传播到具有RowState Proposed的基础DataRow,而原始值将存储在带有RowState Original的DataRow中。当代码更改textBox的值时,不会发生这种情况。根本没有提议的价值。 显然,有一个事件在按代码更改值时不会被触发,但我无法找到它。 有人可以给我一个暗示吗?

代码(简化)

当我在txtBox1中输入内容时,当我离开框时,应该使用文本“Something”更新txtBox2。运行'DisplayData()'时不显示值。如果我在txtBox2中键入内容,则会显示新旧值。     公共部分类frmKunde:表格     {         DataSet dataset = new DataSet();         SqlDataAdapter adapter = new SqlDataAdapter();         BindingSource bSource = new BindingSource();

    public frmKunde(string sql, string sql2, string kid)
     {
         PopFields();
     }

    private void PopFields()
    {
        using (SqlCommand myCommand = new SqlCommand("Select Name, Comment from dBase Where Id='10001'", ConnectionManager.GetManager("SQLConnectionString").Connection))
        {
            adapter.SelectCommand = myCommand;
        }
        adapter.Fill(dataset);

        txtBox1.DataBindings.Add("Text", bSource, "Name");
        txtBox2.DataBindings.Add("Text", bSource, "Comment");
    }

    private void txtBox1_Leave(object sender, EventArgs e)
    {
        txtBox2.Text = "Something";
        Application.DoEvents();
    }

    public void DisplayData()
    {
       DataRowView vVision = ((DataRowView)bSource.Current);
            for (int i = 0; i < vVision.DataView.Table.Columns.Count; i++)
            {
                MessageBox.Show(vVision.Row[i, DataRowVersion.Original] + "\r\n" + vVision.Row[i, DataRowVersion.Proposed]);
            }
        bSource.EndEdit();
    }
 }

0 个答案:

没有答案
相关问题