专门用作于ComboBox.Items的项 /// /// 选择项类,用于ComboBox或者ListBox添加项 /// public class ListItem { private string id = string.Empty; private string name = string.Empty; private object tag = null; public ListItem(string sid, string sname) { id = sid; name = sname; } public ListItem(string sid, string sname,object otag) { id = sid; name = sname; tag = otag; } public override string ToString() { return this.name; } public string Id { get { return this.id; } set { this.id = value; } } public string Name { get { return this.name; } set { this.name = value; } } public object Tag { get { return this.tag; } set { this.tag = value; } } } 但是如下使用时,选择后会抛出一个对象必须实现 IConvertible的错误 注: prop_values是一个List对象 RepositoryItemComboBox editor = pgProperty.RepositoryItems.Add("ComboBoxEdit") as RepositoryItemComboBox; editor.Items.AddRange(prop_values.ToArray()); 查阅了资料后发现,RepositoryItemComboBox 中的项需要实现IConvertible接口,否则的话要用如下语句来解决: editor.ParseEditValue += new ConvertEditValueEventHandler(repositoryItemComboBox_ParseEditValue); void repositoryItemComboBox_ParseEditValue(object sender, ConvertEditValueEventArgs e) { e.Value = e.Value.ToString(); e.Handled = true; } 本文来源:https://www.wddqw.com/doc/117f6ee402768e9950e7380c.html