Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay List contents specific field in a ComboBox (C#)
    text
    copied!<p>Well, my question is a bit silly, but I've tried lots of different thing without result. </p> <p>I have a ComboBox in my main form and I want to point its data source to the public readonly List PriceChanges list declared in the Filters class. No problem with that but I want to list the Description field. </p> <p>I tried to assign the "Description" string to the DisplayMember attribute without success. My ComboBox only lists: "BusinessLogic.PriceChange" for each entry, where BusinessLogic is the name of my Namespace and PriceChange the class.</p> <p>I appreciate any help. </p> <p>Regards</p> <p>That's part of the code of my main form</p> <pre><code> public mainFrm() { InitializeComponent(); prodFilter = new Filters(); cbPriceChanges.DataSource = prodFilter.PriceChanges; cbPriceChanges.DisplayMember = "Description" } </code></pre> <p>That's is part of the code that declares the List object</p> <pre><code>public enum PriceChangeTypes { No_Change, Increased, Decreased, All } public class PriceChange { public String Description; public readonly PriceChangeTypes Type; public delegate bool ComparisonFuntionDelegate(Decimal a); public readonly ComparisonFuntionDelegate ComparisonFunction; public PriceChange(String Description, PriceChangeTypes type , ComparisonFuntionDelegate CompFunc) { this.Description = Description; Type = type; ComparisonFunction = CompFunc; } } public class Filters { public readonly List&lt;PriceChange&gt; PriceChanges = null; public Filters() { PriceChanges = new List&lt;PriceChange&gt;(); PriceChanges.Add(new PriceChange("No Change", PriceChangeTypes.No_Change, PriceChange =&gt; PriceChange == 0)); PriceChanges.Add(new PriceChange("Increased", PriceChangeTypes.Increased, PriceChange =&gt; PriceChange &gt; 0)); PriceChanges.Add(new PriceChange("Decreased", PriceChangeTypes.Decreased, PriceChange =&gt; PriceChange &lt; 0)); PriceChanges.Add(new PriceChange("All", PriceChangeTypes.All, a =&gt; true)); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload