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 閱讀(287) 評論(0)  編輯  收藏 所屬分類: C#Dot.netWinForm


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

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

          統計

          常用鏈接

          留言簿(7)

          隨筆分類

          隨筆檔案

          相冊

          Photo

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 西乌珠穆沁旗| 萨迦县| 西乡县| 股票| 邳州市| 项城市| 宁阳县| 南阳市| 渑池县| 铁岭市| 华阴市| 绥宁县| 岱山县| 富宁县| 柳江县| 尚志市| 康马县| 衡水市| 色达县| 根河市| 雷州市| 克拉玛依市| 英德市| 离岛区| 北辰区| 阜新市| 龙游县| 安阳市| 新津县| 陇川县| 黔西| 搜索| 晋中市| 皮山县| 同德县| 海南省| 兖州市| 桐庐县| 靖江市| 岢岚县| 尉犁县|