[英]How to bind combobox to linq result value only?
I want to bind combobox to value only and distinct name .But I get like this: 我想将组合框绑定到仅值和唯一名称。但是我得到的是这样的:
I want only value eg; 我只想要值,例如;
Ice Box Handle,Green 冰盒把手,绿色
Please answer to me.My code is like this 请回答我。我的代码是这样的
DataTable acc= accessory.GetData(); DataTable acc = annex.GetData();
var query = (from t in acc.AsEnumerable() var query =(从acc.AsEnumerable()中的t
select new { 选择新的{
name = t["type"].ToString(), color = t["color"].ToString() }).Distinct().ToList();
cmbAccessoryName.DataSource = query; cmbAccessoryName.DataSource =查询;
Use ValueMember and DisplayMember property! 使用ValueMember和DisplayMember属性! to display inside the combo and use .Distinct() to filter duplicates! 在组合内显示并使用.Distinct()过滤重复项!
try: 尝试:
DataTable acc= accessory.GetData();
var query = (from t in acc.AsEnumerable()
select new {
description=string.Format("{0},{1}",t["type"].ToString(), color = t["color"].ToString())
}).Distinct().ToList();
cmbAccessoryName.DataSource = query;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.