[原创]C# ComboBox绑定key和value

struct itemEx { public object Value; public string Text; public itemEx(object value, string text) { this.Value = value; this.Text = text; } //重点是override ToString public override string ToString() { return Text; } } ………… //绑定 itemEx item1 = new itemEx(); item1.Text = dsTrDevice.Tables[0].Rows[i][0].ToString(); item1.Value = dsTrDevice.Tables[0].Rows[i][1]; ComboBox1.Items.Add(item1); //反转换 itemEx item = new itemEx(); item = (itemEx)(this.ComboBox1.SelectedItem); string strValue = item.Value.ToString().Trim();

posted on 2009-06-29 15:33  highmayor  阅读(2043)  评论(1编辑  收藏  举报

导航