锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲狠狠成人综合网,亚洲人色大成年网站在线观看,亚洲欧洲日本在线观看http://www.tkk7.com/programmer/category/27887.htmlzh-cnFri, 07 Dec 2007 06:21:51 GMTFri, 07 Dec 2007 06:21:51 GMT60Refresh related controls' value when data changed using DataBind in Winformhttp://www.tkk7.com/programmer/archive/2007/08/29/165569.htmlwadewadeWed, 29 Aug 2007 02:31:00 GMThttp://www.tkk7.com/programmer/archive/2007/08/29/165569.htmlhttp://www.tkk7.com/programmer/comments/165569.htmlhttp://www.tkk7.com/programmer/archive/2007/08/29/165569.html#Feedback0http://www.tkk7.com/programmer/comments/commentRss/165569.htmlhttp://www.tkk7.com/programmer/services/trackbacks/165569.htmlGoal:
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();