求帮助?怎么解决combobox绑定数据源的内容全是一样的情况

.Net技术 码拜 8年前 (2016-05-19) 986次浏览
代码如下:
实现层:
List<Device> typeidList = new OperateModel().QueryType();
cbx_type.DataSource = typeidList;
模型层:
public class Device
{
public int Id { get; set; }
public string Name { get; set; }
public int ModelId { get; set; }
public int TypeId { get; set; }
}
操作层:
OperateModel类:
public List<Device> QueryType()
{
return new DataQuery().QueryTypeId();
}
QueryType类:
public List<Device> QueryTypeId()
{
String strsql = “select TypeId from Device Where  Order By Id”;
return new SQLHelperChange().ReaderToList<Device_Record>(new SQLHelper().SelectReader(strsql));
}
最后combobox实现的结果是DeviceModel.Device,本人知道是属性被绑定进来,想知道下怎么可以把TypeId属性绑定进来?
解决方案

31

这样?

List<Device> typeidList = new OperateModel().QueryType();
cbx_type.DataSource = typeidList
cbx_type.DisplayMember="TypeId"

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求帮助?怎么解决combobox绑定数据源的内容全是一样的情况
喜欢 (0)
[1034331897@qq.com]
分享 (0)