关于SetEditorBindingValue方法的使用
作者:C/S框架网  发布日期:2012/10/05 16:50:36
  关于SetEditorBindingValue方法的使用

关于SetEditorBindingValue方法的使用

功能需求

在开发应用中,通常当选择一个值时要自动带出相关数据(给其它输入框组件赋值),比如一个选择客户的LookupEdit组件,取名为txtCustomer,选择客户的同时要自动带出客户的名称、联系人以及联系电话在对应的输入框中显示出来。我们可以在EditValueChanged、Validating、或者TextChanged事件内处理。

有一种异常情况

假设在EditValueChanged事件内处理上述需求,当选择客户后能自动带出联系人及电话号码,但是客户选择框本身被莫名其妙清空了!

原因:若在EditValueChanged事件内给其他绑定数据源的组件赋值时,会重置当前组件的EditValue的值。


解决方案

必须在EditValueChanged事件内第一行代码调用SetEditorBindingValue(txtCustomer,txtCustomer.EditValue),但是这种处理可能造成死循环,给EditValue赋值时又调用了EditValueChanged事件。

改为以下写法,注意第3个参数:

SetEditorBindingValue(txtCustomer,txtCustomer.EditValue,false);


完整的写法如下:


  private void txtCustomer_EditValueChanged(object sender, EventArgs e)

  {//当选择客户,自动带出客户的名称、联系人、联系电话

 

     //不给自己的EditValue赋值,参数setEditorValuefalse

     EditorBinding.SetEditorBindingValue(txtCustomer, txtCustomer.EditValue, false);

 

     //根据编号编号查询客户详细资料

     Customer customer = new bllCustomer().Find(txtCustomer.EditValue.ToString());

 

     //除sender外,给其它绑定的数据源及EditValue赋值,setEditorValue=true

     EditorBinding.SetEditorBindingValue(txtCustomerName, customer.CustomerName, true);

     EditorBinding.SetEditorBindingValue(txtCustomerAttn, customer.Attn, true);

     EditorBinding.SetEditorBindingValue(txtCustomerTel, customer.Tel, true);

  }



VIP用户下载附件:
点击下载附件 点击下载附件 (如下载失败,请邮件通知我们寄回给您,或QQ:23404761留言.)
上一篇 下一篇