您将使用哪个事件处理程序来捕获绑定组合框中项目的更改



我有一个绑定的组合框,其中包含客户名称列表。我尝试了在更改组合框中的名称时触发的key_down。我想要的是将触发的事件处理程序,因为该名称正在更改(如拼写),而不一定要更改为列表中的其他名称。我想我需要写一段代码来测试拼写的变化。是否有一个事件处理程序可以完成这项工作?

我在Visual Studio中使用Windows窗体上的C#和SQL Server 2008

public Customer_Info_Form()
        {
            InitializeComponent();
            button_Add_Customer.Visible = true;
            button_Add_Location.Visible = true;
            button_Save_Customer.Visible = false;
            button_Cancel_Customer_Add.Visible = false;
        }
private void Customer_Info_Form_Load(object sender, EventArgs e)
        {
            try
            {
                this.customerTableAdapter.Fill(this.customer_Info_DataSet.Customer);
                this.customer_ShipTableAdapter.Fill(this.customer_Info_DataSet.Customer_Ship);
                this.termsTableAdapter.Fill(this.terms_DataSet.Terms);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
private void text_Changed(object sender, EventArgs e)
        {
            button_Add_Customer.Visible = false;
            button_Add_Location.Visible = false;
            button_Save_Customer.Visible = true;
            button_Cancel_Customer_Add.Visible = true;
        }

表单加载时会触发"text_Changed"事件。在实际更改文本之前,它不应该启动。我选择"取消",按钮被重置,一旦我选择了不同的客户名称,事件就会再次触发。实际上,我没有更改任何文本。如何保持"text_Changed"事件不被触发,直到文本被实际更改?

您可以使用TextChanged事件

只要组合框的值发生变化,就会触发它。

当我尝试TextChanged事件时,它会在加载表单时立即启动,当我在绑定组合框中选择不同的名称时,它也会启动,而不是在文本实际更改时。

为了捕捉对组合框中任何选定项的文本的更改,我使用KeyDown事件捕捉对名称或表单上任何控件的更改。

最新更新