Loading...

          java .net

          ComboBox 手動綁定數據項


          ===========ValueObject.cs============

          using System;
          using System.Collections.Generic;
          using System.Text;

          namespace psms.util
          {
              class ValueObject
              {
                  private string value;
                  private string text;

                  public ValueObject(string v, string t)
                  {
                      this.value = v;
                      this.text = t;
                  }

                  public string Value
                  {
                      get { return this.value;}
                  }
                  public string Text
                  {
                      get { return this.text; }
                  }

              }
          }

          ===============綁定數據===============

          this.combIn_Acc.Items.Add(new util.ValueObject("", ""));
          this.combIn_Acc.Items.Add(new util.ValueObject("0","未做帳"));
          this.combIn_Acc.Items.Add(new util.ValueObject("1", "已做帳"));
                     
          this.combIn_Acc.ValueMember = "value";
          this.combIn_Acc.DisplayMember = "text";
          this.combIn_Acc.SelectedIndex = 0;


          ================取值==================


          if (this.combIn_Acc.SelectedIndex >= 0)
          {
             if (((util.ValueObject)this.combIn_Acc.SelectedItem).Value.ToString() != "")
             {
                 condition.Append(" and in_acc = ").Append(((util.ValueObject)this.combIn_Acc.SelectedItem).Value.ToString()).Append(" ");
             }
          }


          不知道為什么this.combIn_Acc.SelectedValue總是報空指針異常,想不明白,換了上面的取值方法終于可行了

          posted on 2008-08-26 22:06 閱讀(920) 評論(2)  編輯  收藏

          評論

          # re: ComboBox 手動綁定數據項 2012-05-31 22:46 xz

          高手 好貼。有時候不從數據庫 幾個字段。手動添加。這樣不錯  回復  更多評論   

          # re: ComboBox 手動綁定數據項 2012-05-31 22:47 xz

          不錯貼子 有時候 手動添加幾條數據 不要從數據庫取   回復  更多評論   


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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           

          公告

          希望有一天

          我能用鼠標雙擊我的錢包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導航

          <2008年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          統計

          常用鏈接

          留言簿(6)

          隨筆分類(102)

          隨筆檔案(398)

          文章分類

          文章檔案(10)

          有趣網絡

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 英超| 囊谦县| 监利县| 咸丰县| 岱山县| 德庆县| 青河县| 积石山| 迁西县| 徐水县| 准格尔旗| 沈阳市| 囊谦县| 天门市| 金山区| 景泰县| 岐山县| 通州市| 桑日县| 濮阳县| 武平县| 海兴县| 南阳市| 林芝县| 密云县| 文登市| 渭南市| 垣曲县| 安图县| 桂平市| 罗平县| 嘉义县| 金山区| 黎川县| 平江县| 三穗县| 阳山县| 莒南县| 曲周县| 渭源县| 丹棱县|