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 閱讀(293) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): C#Dot.netWinForm


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

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

          統(tǒng)計(jì)

          常用鏈接

          留言簿(7)

          隨筆分類(lèi)

          隨筆檔案

          相冊(cè)

          Photo

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 安塞县| 莱芜市| 莱州市| 南皮县| 兰考县| 沭阳县| 黄山市| 策勒县| 泰州市| 新乡县| 广河县| 新疆| 罗江县| 奈曼旗| 凌云县| 泸水县| 绥德县| 米林县| 九寨沟县| 崇明县| 成安县| 盘山县| 张北县| 安多县| 桑植县| 嘉荫县| 灵台县| 仪陇县| 辽阳县| 华容县| 土默特右旗| 高唐县| 呼图壁县| 监利县| 栾城县| 宁阳县| 叶城县| 卢龙县| 浑源县| 海伦市| 阿拉善盟|