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)論排行榜

          主站蜘蛛池模板: 富平县| 贵阳市| 河南省| 赤水市| 临漳县| 诏安县| 蕉岭县| 富裕县| 若尔盖县| 遵化市| 缙云县| 莱芜市| 谷城县| 灵武市| 萍乡市| 海安县| 青田县| 澜沧| 榆中县| 老河口市| 陆河县| 屏南县| 香河县| 金昌市| 桑日县| 牟定县| 旌德县| 渭源县| 平顶山市| 渑池县| 边坝县| 寿光市| 浠水县| 维西| 枣庄市| 吉首市| 罗平县| 玛纳斯县| 金门县| 通城县| 大新县|