Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Trade.TradeStatus is an instance of the class TradeOrderStatus</p> </blockquote> <p>You mention it is a class; is it the <strong>same</strong> instance as one of those in the data-bound list? It needs to find an equality match. Alternatively, you can override <code>Equals</code> (and <code>GetHashCode()</code> - always keep the two in sync) to achieve the same thing.</p> <hr> <p>(edit)</p> <p>The simplest way to fix it is to bind to <code>SelectedValue</code>; with the "full" example (below), something like:</p> <pre><code>cbo.DisplayMember = cbo.ValueMember = "Name"; ... btn.Click += delegate { cbo.SelectedValue = GetCurrentStatus().Name; }; </code></pre> <p>(edit)</p> <p>Here's a C# example (sorry, my VB-fu is weak) of providing custom equality of the different statuses - note the "uncomment to fix":</p> <pre><code>using System.Windows.Forms; using System.Collections.Generic; class MyStatus { public MyStatus(string name) { Name = name; } public string Name { get; private set; } public override string ToString() {return Name; } /* uncomment to fix public override bool Equals(object obj) { MyStatus other = obj as MyStatus; return other != null &amp;&amp; other.Name == this.Name; } public override int GetHashCode() {return Name.GetHashCode(); } */ } static class Program { static void Main() { ComboBox cbo = new ComboBox(); cbo.DataSource = GetStatuses(); Button btn = new Button(); btn.Click += delegate { cbo.SelectedItem = GetCurrentStatus(); }; btn.Text = "Set Status"; btn.Dock = DockStyle.Bottom; Application.Run(new Form { Controls = { cbo, btn } }); } static List&lt;MyStatus&gt; GetStatuses() { List&lt;MyStatus&gt; stats = new List&lt;MyStatus&gt;(); stats.Add(new MyStatus("Open")); stats.Add(new MyStatus("Pending")); stats.Add(new MyStatus("Closed")); return stats; } static MyStatus GetCurrentStatus() { return new MyStatus("Closed"); } } </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