Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5945667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:42:50+00:00 2026-05-22T16:42:50+00:00

I have a BindingList with my class where I would like to populate a

  • 0

I have a BindingList with my class where I would like to populate a ComboBox using a property of it so when my list changes the ComboBox would change as well.

public class UserAccess
{
    public override string ToString()
    {
        return Access;
    }
    public int AccessId { get; set; }
    public string Access { get; set; }
    public List<string> Command = new List<string>();

    public bool HasCommand(string cmd)
    {
        return this.Command.Any(x => x == cmd);
    }
}

public BindingList<UserAccess> accessList = new BindingList<UserAccess>();

On my form load I assign it to the ComboBox:

myComboBox.DataSource = accessList;

I want to populate the box with Access or with the AccessId as value and Access as the printed name.

Problem is that it will print only the last item of the list to the combobox what am I doing wrong ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:42:50+00:00Added an answer on May 22, 2026 at 4:42 pm

    Use DisplayMember to specify what field to use for display in the ComboBox.
    Make accessList readonly to guarantee that you never recreate a new instance of the list. If you don’t make it readonly, this may introduce a subtle bug, if you don’t reassign DataSource whenever you recereate accessList.

    private readonly BindingList<UserAccess> accessList = new BindingList<UserAccess>();
    
    public Form1()
    {
        InitializeComponent();
    
        comboBox1.ValueMember = "AccessId";
        comboBox1.DisplayMember = "Access";
        comboBox1.DataSource = accessList;
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        accessList.Add(new UserAccess { AccessId = 1, Access = "Test1" });
        accessList.Add(new UserAccess { AccessId = 2, Access = "Test2" });
    }
    

    If you need to be able to change items properties in accessList (like accessList[0].Access = "Test3") and see the changes reflected in UI, you need to implement INotifyPropertyChanged.

    For example:

    public class UserAccess : INotifyPropertyChanged
    {
        public int AccessId { get; set; }
    
        private string access;
    
        public string Access
        {
            get
            {
                return access;
            }
    
            set
            {
                access = value;
                RaisePropertyChanged("Access");
            }
        }
    
        private void RaisePropertyChanged(string propertyName)
        {
            var temp = PropertyChanged;
            if (temp != null)
                temp(this, new PropertyChangedEventArgs(propertyName));
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a BindingList<> of a class set to the DataSource property of a
I have the following code: public partial class Form1 : Form { public BindingList<Class>
I have overridden the ApplySortCore method for a custom BindingList like so: public void
I would like to make a class based on interfaces such as a list
I have a BindingList that I would like to use for a datasource on
I have a class, say DerivedBindingList<T> , which is derived from BindingList<T> . I
I have a DataGridView populated with a BindingList . This list gets saved into
So, I have a DataGridView using as datasource a BindingList DataGridView.DataSource = new BindingList<Car>{...}
I have a BindingList<T> which is bound to a datagridview. One property in my
This a data binding question in C#. I have a simple Person class: public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.