给combobox添加值的问题,各位请进~~

kapil 2005-04-26 01:19:15
这样可以添加元素:
=============================
for( int i = 0; i < this.ds.Tables[table_name].Rows.Count; i++)
{
cb.Items.Add(this.ds.Tables[table_name].Rows[i][1].ToString());
}

===============================
但是如果想给元素添加对应的值该怎么写呢?类似网页中的
“<select><option value="xx">text</option></select>”中的xx
多谢~~
...全文
449 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
李天平 2005-08-01
  • 打赏
  • 举报
回复
如此添加成对的值;
ArrayList list = new ArrayList();
list.Add (new DictionaryEntry ("1","投诉"));
list.Add (new DictionaryEntry ("2","举报"));
list.Add (new DictionaryEntry ("3","建议"));
list.Add (new DictionaryEntry ("4","表扬"));
list.Add (new DictionaryEntry ("5","其它"));

cbBoxLeiXing.DataSource =list;
cbBoxLeiXing.DisplayMember ="Value";
cbBoxLeiXing.ValueMember ="Key";
syfsz 2005-04-26
  • 打赏
  • 举报
回复
public class ItemVO : System.Object
{
public string id;
public string desc;

public ItemVO(string Id, string Desc)
{
this.id = Id;
this.desc = Desc;
}

public override string ToString()
{
return this.desc;
}

public override bool Equals(System.Object obj)
{
if (this.GetType().Equals(obj.GetType()))
{
ItemVO that=(ItemVO) obj;
return (this.id.Equals(that.id));
}
return false;
}
public override int GetHashCode()
{
return this.id.GetHashCode();;
}
}

================
comboBox1.Items.Add(new ItemVO(id,name));
((ItemVO)comboBox1.SelectedItem).id
((ItemVO)comboBox1.SelectedItem).desc
goldentimecym 2005-04-26
  • 打赏
  • 举报
回复
Winform里面的ComboBox只有绑定的时候才能设定Text和Value
用items.add()是没有办法设定Value的
sophialmy82 2005-04-26
  • 打赏
  • 举报
回复
放在hashtable中,再取。
fifadeke 2005-04-26
  • 打赏
  • 举报
回复
不好意思哦,我那个是WEB的,WINFORM的不是很清楚了
lovefootball 2005-04-26
  • 打赏
  • 举报
回复
cs中的comboBox好像是没有value的吧
kapil 2005-04-26
  • 打赏
  • 举报
回复
2楼的兄弟,我这里报错,说没有value这个属性,我的程序是在winform中的~~~
fifadeke 2005-04-26
  • 打赏
  • 举报
回复
this.ddlXq_id.Items.Clear();
ArrayList array2 = new ArrayList();
ArrayList array1 = Pub.GetCol1("SELECT [ID],[NAME] FROM TABLE_XQ_PARA",ref array2);
for(int i=0;i<array1.Count;i++)
{
this.ddlXq_id.Items.Add(array2[i].ToString().Trim());
this.ddlXq_id.Items[i].Value = array1[i].ToString().Trim();
}
kapil 2005-04-26
  • 打赏
  • 举报
回复
up

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧