combobox的使用

来源:互联网 发布:windows拷贝linux文件 编辑:程序博客网 时间:2024/05/08 03:40

今天对这个鬼东西有了更深的了解!

首先对它的添加有两种方式,第一是手动添加元素,接下来是通过数据库获取的数据源

方式一:

   this.cbProjectType.DropDownStyle = ComboBoxStyle.DropDownList;
   this.cbProjectType.Items.Add ( new DictionaryEntry (1,"WebApplication_.NET_SqlServer2000") );
   this.cbProjectType.Items.Add ( new DictionaryEntry (2,"WindowsApplicaton_.NET_SqlServer2000"));
   this.cbProjectType.DisplayMember = "value";
   this.cbProjectType.ValueMember = "key"; 

   DictionaryEntry Item =(DictionaryEntry) this.cbProjectType.SelectedItem;

然后可以调用Item.Key.Tostring()即可

方法二:

   this.lbPropertyUnUsed.DataSource = this.NewPropertyDataSet;
   this.lbPropertyUnUsed.DisplayMember = "Property_PropertyName";
   this.lbPropertyUnUsed.ValueMember = "Property_ID";

 

对于选择的Item的value 可以调用SelectedValue

但是对于有个很郁闷的问题就是对于Items集合里面的东西不知道怎么选取Value值,最后偷懒首先让其变成

Selected然后再用上面的函数,唉!我估计是应该有一个类型的东西来接收传回来的这个SelectItem吧!不晓

得了。。。

 

再有就是今天做成了那个见鬼的控件,嘿嘿!

原创粉丝点击