Tao

Tao obeys its own inherent Nature

Refresh related controls' value when data changed using DataBind in Winform

Goal:

Use a ComboBox to select an item, and save the selected item's value to some textboxes. each control is using databinding.

Problems:

1. set control's value when comboBox changed, after the comboBox lost focus, the text was lost since the controls reload the data from binding source.

2. set binding source's value, the text will be set only when the comboBox lost focus. but we want to set the text immediately when the comboBox changed.

Solution:

set binding source's value, and call comboBox's writeValue for comboBox. this will write the comboBox's value to datasource, and reload all controls' value.

Test selectedTest = (Test)comboBox1.SelectedItem;

Test test = (Test)bindingSource1.DataSource;
if (selectedTest == null || test == null)
return;

//save the selected value to the binding source test.Name = selectedTest.Name; test.Value = selectedTest.Value; //this will write the comboBox's value to datasource, and reload all controls' value comboBox1.DataBindings["SelectedValue"].WriteValue();

 

posted on 2007-08-29 10:31 wade 阅读(262) 评论(0)  编辑  收藏 所属分类: C#Dot.netWinForm


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2007年8月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

统计

常用链接

留言簿(7)

随笔分类

随笔档案

相册

Photo

搜索

最新评论

阅读排行榜

评论排行榜