从数据库读出了数据组成一个List ,student有两个属性id和comment.我想要在propertygrid下拉显示comment(张三), 实际值是id(1).应该如何实现呢。目前只能实现下拉,代码如下
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
ListAttribute lst = (ListAttribute)context.PropertyDescriptor.Attributes[typeof(ListAttribute)];
StandardValuesCollection vals = new TypeConverter.StandardValuesCollection(lst.listComment);
return vals;
}
public class ListAttribute : Attribute
{
public List<Student> lists;
public List<string> listComment;
public ListAttribute()
{
lists = Model_sys_node_type.GetNode_type_Model_list();//.ToArray()从List<System.String>转到System.String[],listS.ToArray()
listComment = lists.Select(x => x.Comment).ToList();
}
}
但是未能实现,保存到数据库使用 id .请教大家如何实现呢?