Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bind to a combobox control without add code to the code behind in Winforms?
    primarykey
    data
    text
    <p>I am trying to find the most elegant way I can use to bind to a combobox on a Windows Form without using code behind. On the form I have a combobox with two binding sources. One is bound to a Controller, which contains a List of Countries and when called populates this list. The other binding source is bound to the other binding source bound to the controller and I have set the data members as the collection of 'Countries'. I am using EF5 to fetch my data in the controller. However, from what I have done I cannot get the combobox populated when I run my application. Please assist on what I am missing in terms of databind? Please find my code below:</p> <pre><code> static class Program { /// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); IUnityContainer container = new UnityContainer(); Modules.RegisterModules(container); var controller = container.Resolve&lt;IController&gt;(); Application.Run(new TestForm(controller)); } } internal static class Modules { public static void RegisterModules(IUnityContainer container) { container.RegisterType&lt;IController, GeoController&gt;(); container.RegisterType&lt;IModelContainer, GeoModelContainer&gt;(); } } public class GeoController : IController, INotifyPropertyChanged { private List&lt;Continent&gt; _continents; private List&lt;Country&gt; _countries; private List&lt;City&gt; _cities; IModelContainer Container { get; set; } public GeoController(IModelContainer container) { Container = container; Countries = Container.Countries.ToList(); } #region Properties public List&lt;Country&gt; Countries { get { return _countries; } set { _countries = value; OnPropertyChanged(); } } #endregion public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } } public interface IController { List&lt;Country&gt; Countries { get; set; } } public partial class TestForm : Form { IController Controller { get; set; } public TestForm(IController controller) { InitializeComponent(); Controller = controller; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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