这样可以添加元素:
=============================
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
多谢~~
=============================
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
多谢~~
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();
}
用items.add()是没有办法设定Value的
{
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
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";