c# - Add an object to WPF Combo box Items collection, but only show specific property to the client -
if have class like:
public class product { public int productid { get; set; } public string productname { get; set; } }
and have collection of products (stored in products variable)
foreach (var product in products) { productcombobox.items.add(product.productname); }
this adds product names combo box, that. there way this:
foreach (var product in products) { productcombobox.items.add(product); }
but when combo box opened, show product names (but store entire product object in combo box? thanks.
you can use displaymemberpath property this.
<combobox displaymemberpath="productname"/>
Comments
Post a Comment