Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
UltraComboEditor and List<T> as DataSource
posted

I created a small helper class:

    public class ComboHelper
    {
        public int ValueMember;
        public string DisplayMember;
    }

I want to create a List<ComboHelper> and bind that to a UltraComboEditor control:

List<ComboHelper> comboDataSource = new List<ComboHelper>();
ComboHelper comboHelper = new ComboHelper { ValueMember = 1, DisplayMember = "ID" };
comboDataSource.Add(comboHelper);
comboHelper = new ComboHelper { ValueMember = 2, DisplayMember = "Collateral" };
comboDataSource.Add(comboHelper);

cmbFilter.DataSource = comboDataSource;
cmbFilter.DisplayMember = "DisplayMember";
cmbFilter.ValueMember = "ValueMember";

I run the app and nothing shows in the combo box.  What am I missing? [I know it's something simple...still trying to get the hang of these controls]

 

  • 45049
    Verified Answer
    posted

    The .NET BindingManager will expose public properties, but not public fields.

    If you're using a .NET 3.5 application (and it looks like you are from your other sample code), change your class definition as follows:

        public class ComboHelper
        {
            public int ValueMember { get; set; };
            public string DisplayMember { get; set; };
        }

    If you're using .NET 2.0, you'll need to make these private fields, and then create public properties that get and set those fields.