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 660639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:10:44+00:00 2026-05-13T23:10:44+00:00

I’m using winforms and I’ve got a comboBox that represents an IQueryable. Below the

  • 0

I’m using winforms and I’ve got a comboBox that represents an IQueryable. Below the combobox is a series of textboxes that I would like to be bound to the currently selected from the combo box.

Here is my code.

public partial class TestForm : Form
{
    public DataClassesDataContext DataContext;

    public IQueryable<T> datasource;

    // Ctor
    public TestForm()
    {
    InitializeComponent();

    // L2S data context
    this.DataContext = new DataClassesDataContext();

    // Get the variable for the data source
    this.datasource = this.DataContext.Ts;

    // setup the binding for the combobox
    this.comboBox1.DataSource = this.datasource;
    this.comboBox1.DisplayMember = "Description";
    this.comboBox1.ValueMember = "Id";

    // assign the databindings of the text boxes to the selectedItem of the combo box    
    // this is where the problem is, afaik
    TId.DataBindings.Add(new Binding("Text", this.comboBox1.SelectedItem, "Id"));
    TUser.DataBindings.Add(new Binding("Text", this.comboBox1.SelectedItem, "User"));
    TDescription.DataBindings.Add(new Binding("Text", this.comboBox1.SelectedItem, "Description"));
}

Doing this binds everything, When I change the values in the text boxes, it updates the initially selected item in the combo box just fine. Even when I change the description, it updates the displayed text in the drop don, all that is great.

However, when I select a different item from the drop down, the text boxes don’t bind to that newly selected item, they stay bound to the old one.

Do I need to remove and re-add my bindings every time the selection changes on the combo box?

  • 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-13T23:10:44+00:00Added an answer on May 13, 2026 at 11:10 pm

    Use a BindingSource rather than directly relying upon the L2S data context. The binding source uses a concurrency manager to handle all the updating for you and the L2S does not

    Working code:

    public partial class TestForm : Form
    {
        public DataClassesDataContext DataContext;
    
        // Incorrect: public IQueryable<T> datasource;
        // Correct:
        public BindingSource TsDataSource;
    
        // Ctor
        public TestForm()
        {
        InitializeComponent();
    
        // L2S data context
        this.DataContext = new DataClassesDataContext();
    
        // Get the variable for the data source
        // Incorrect: this.datasource = this.DataContext.Ts;
        // Correct:
        this.TsDataSource = new BindingSource();
        this.TsDataSource.DataSource = this.DataContext.Ts;
    
        // setup the binding for the combobox
        this.comboBox1.DataSource = this.TsDataSource;
        this.comboBox1.DisplayMember = "Description";
        this.comboBox1.ValueMember = "Id";
    
        // assign the databindings of the text boxes to the selectedItem of the combo box    
        TId.DataBindings.Add(new Binding("Text", this.TsDataSource, "Id"));
        TUser.DataBindings.Add(new Binding("Text", this.TsDataSource, "User"));
        TDescription.DataBindings.Add(new Binding("Text", this.TsDataSource, "Description"));
    }
    

    More about BindingSource from the source (couldnt resist):

    The BindingSource component serves
    many purposes. First, it simplifies
    binding controls on a form to data by
    providing currency management, change
    notification, and other services
    between Windows Forms controls and
    data sources. This is accomplished by
    attaching the BindingSource component
    to your data source using the
    DataSource property. For complex
    binding scenarios you can optionally
    set the DataMember property to a
    specific column or list in the data
    source. You then bind controls to the
    BindingSource. All further interaction
    with the data is accomplished with
    calls to the BindingSource component.
    For examples on how the BindingSource
    can simplify the binding process, see
    How to: Bind Windows Forms Controls to
    DBNull Database Values and How to:
    Handle Errors and Exceptions that
    Occur with Databinding. Navigation and
    updating of the data source is
    accomplished through methods such as
    MoveNext, MoveLast, and Remove.
    Operations such as sorting and
    filtering are handled through the Sort
    and Filter properties. For more
    information on using sorting and
    filtering with the BindingSource, see
    How to: Sort and Filter ADO.NET Data
    with the Windows Forms BindingSource
    Component.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 324k
  • Answers 324k
  • 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 The function hasn't been defined yet, so the name 'isVowel'… May 14, 2026 at 1:16 am
  • Editorial Team
    Editorial Team added an answer I'm answering this in a slightly different way - as… May 14, 2026 at 1:16 am
  • Editorial Team
    Editorial Team added an answer One of the reason for the loss of precision is… May 14, 2026 at 1:16 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
In order to apply a triggered animation to all ToolTip s in my app,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I've got a string that has curly quotes in it. I'd like to replace

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.