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


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


          網站導航:
           

          導航

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

          統計

          常用鏈接

          留言簿(7)

          隨筆分類

          隨筆檔案

          相冊

          Photo

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 江油市| 女性| 杂多县| 安化县| 油尖旺区| 南昌县| 三门县| 大洼县| 烟台市| 垣曲县| 古浪县| 壤塘县| 昆明市| 陵水| 景东| 普定县| 民勤县| 甘泉县| 新余市| 保德县| 卢湾区| 突泉县| 九龙城区| 台安县| 奈曼旗| 左贡县| 叙永县| 新巴尔虎右旗| 朝阳市| 于田县| 瓮安县| 永和县| 宿松县| 临高县| 芜湖县| 治县。| 团风县| 和平县| 镇康县| 勐海县| 盈江县|