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

  • Home
  • SEARCH
  • 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 641169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:02:00+00:00 2026-05-13T21:02:00+00:00

Concerning data binding I have these classes: public class Foo : List<Bar> { public

  • 0

Concerning data binding I have these classes:

public class Foo : List<Bar>
{
    public string FooName { get; set; }
}

public class Bar
{
    public string BarName { get; set; }
    public string BarDesc { get; set; }
}

And I have a List<Foo>

I would like to have Foo items in ComboBox, and Bar items in ListBox. When I change selected item in ComboBox, I want ListBox to change. When I change selected item in ListBox I would like to have TextBox filled with BarDesc.

Following works only for ListBox and ComboBox:

comboBox1.DataSource = foos;
comboBox1.DisplayMember = "FooName";
listBox1.DataBindings.Add("DataSource", foos, "");
listBox1.DisplayMember = "BarName";

I don’t now how to bind selected Bar in ListBox to TextBox.Text property. Maybe added binding for listBox1 is not a good idea.

Maybe I should do something like that:

((CurrencyManager)listBox1.BindingContext[foos]).CurrentChanged += new EventHandler((o, a) =>
{
    textBox1.DataBindings.Clear();
    textBox1.DataBindings.Add("Text", listBox1.DataSource, "BarDesc");
});

How can I resolve my problem?

  • 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-13T21:02:01+00:00Added an answer on May 13, 2026 at 9:02 pm

    To make all this work, I had to add the Items property to the Foo class. This is the “link/relationship” between the two binding sources.

    public partial class Form1 : Form {
        public class Foo : List<Bar> {
            public string FooName { get; set; }
            public Foo(string name) { this.FooName = name; }
            public List<Bar> Items { get { return this; } }
        }
        public class Bar {
            public string BarName { get; set; }
            public string BarDesc { get; set; }
            public Bar(string name, string desc) {
                this.BarName = name;
                this.BarDesc = desc;
            }
        }
        public Form1() {
    
            InitializeComponent();
    
            List<Foo> foos = new List<Foo>();
    
            Foo a = new Foo("letters");
            a.Add(new Bar("a", "aaa"));
            a.Add(new Bar("b", "bbb"));
            foos.Add(a);
    
            Foo b = new Foo("digits");
            b.Add(new Bar("1", "111"));
            b.Add(new Bar("2", "222"));
            b.Add(new Bar("3", "333"));
            foos.Add(b);
    
            //Simple Related Object List Binding
            //http://blogs.msdn.com/bethmassi/archive/2007/04/21/simple-related-object-list-binding.aspx
    
            BindingSource comboBoxBindingSource = new BindingSource();
            BindingSource listBoxBindingSource = new BindingSource();
    
            comboBoxBindingSource.DataSource = foos;
            listBoxBindingSource.DataSource = comboBoxBindingSource;
            listBoxBindingSource.DataMember = "Items";
    
            comboBox1.DataSource = comboBoxBindingSource;
            comboBox1.DisplayMember = "FooName";
    
            listBox1.DataSource = listBoxBindingSource;
            listBox1.DisplayMember = "BarName";
    
            textBox1.DataBindings.Add("Text", listBoxBindingSource, "BarDesc");
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 318k
  • Answers 318k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I found the answer here: http://forums.silverlight.net/forums/p/149264/377212.aspx MVC recognizes the MetaDataType… May 14, 2026 at 12:01 am
  • Editorial Team
    Editorial Team added an answer K, I looked at all the given answers quite seriously,… May 14, 2026 at 12:01 am
  • Editorial Team
    Editorial Team added an answer Build the binary from source if the distro supplied one… May 14, 2026 at 12:01 am

Related Questions

Trying to implement what I thought was a simple concept. I have a user
This is a two part question. The first is a specific question about DataSets
I'm not interested in answers concerning client side validation or model binding. Really, this
I am using Web Flow 2.0.7 with Spring MVC and Hibernate. My problem is
We have an app that uses simple one way binding with a GridView to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.