Reputation: 1550
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();
var query = (from t in acc.AsEnumerable()
select new {
name = t["type"].ToString(), color = t["color"].ToString() }).Distinct().ToList();
cmbAccessoryName.DataSource = query;
Upvotes: 0
Views: 3233
Reputation: 13086
Use ValueMember and DisplayMember property! to display inside the combo and use .Distinct() to filter duplicates!
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;
Upvotes: 1