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


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


          網站導航:
           

          導航

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

          統計

          常用鏈接

          留言簿(7)

          隨筆分類

          隨筆檔案

          相冊

          Photo

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 滕州市| 崇文区| 贡嘎县| 永泰县| 高雄县| 金华市| 海城市| 灌阳县| 阿坝县| 靖远县| 鄯善县| 深泽县| 怀来县| 武宣县| 宿州市| 江油市| 抚顺县| 广东省| 灵台县| 清流县| 宝兴县| 长岛县| 益阳市| 乐都县| 墨江| 延吉市| 襄城县| 东乡族自治县| 富宁县| 林芝县| 儋州市| 百色市| 松滋市| 宁阳县| 桐庐县| 广平县| 德昌县| 梅州市| 大连市| 大理市| 陈巴尔虎旗|