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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:49:51+00:00 2026-05-11T17:49:51+00:00

I am a little bit puzzled as to how I can optimize my program

  • 0

I am a little bit puzzled as to how I can optimize my program by utlizing DataBindings. My program uses several Linq2SQL bound Objects storing the Data. All ORM objects are stored in a hierarchy. In a second GUI project I am displaying this data in some Text and Combo Box fields.

The data structure hierarchy is as follows:

  • JobManager contains a Dictionary of Jobs
  • Each Job contains a Dictionary of Jobitems
  • Each Jobitem contains exactly one Article

Job, Jobitem and Article each are Linq2SQL objects, representing a ORM.

Now I have a GUI with 2 list views and a tab pane. The tab pane displays the properties of jobs, jobitems and articles and offers the possibility to modify jobs and jobitems. The GUI should behave like this:

  1. When a Job is selected in the first ListView, the related jobitems will be shown in the second ListView and detail information about the job are shown in the tab pane.
  2. When a Jobitem is selected in the second ListView, the jobitem details and article details are shown in the tab pane, but only the Jobitem info is editable.
  3. When changes are done, the user has to intentionally save them. Otherwise the changes should be discarded and not synced to the database.

How can I achieve this behaviour with DataBinding?

Especially, can I bind a complete collection to a single TextField once and shift through its position dictated by the selection in the ListViews? Or do I have to add and remove individual DataBindings on a per Job basis for every selection the user conducts?

  • 1 1 Answer
  • 3 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-11T17:49:51+00:00Added an answer on May 11, 2026 at 5:49 pm

    Do you really mean “Dictionary”? Winform binding is OK with lists (IList/IListSource), but not with dictionary. Additionally, ListView isn’t quite as easy to bind to as some other controls.

    Other than that, it should work purely using the mapping names – I’ll try to do a simple example…


    Edit with basic example from Northwind; note that the data-context should ideally not be long lived; you may also want to look at things like repository implementations rather than direct binding:

    using System;
    using System.Windows.Forms;
    using SomeNamespaceWithMyDataContext;
    static class Program
    {
        [STAThread]
        static void Main() {
            MyDataContext ctx = new MyDataContext();
            BindingSource custs = new BindingSource() {
                DataSource = ctx.Customers};
    
            BindingSource orders = new BindingSource {
                DataMember = "Orders", DataSource = custs};
    
            Button btn;
            using (Form form = new Form
            {
                Controls = {
                    new DataGridView() {
                        DataSource = orders, DataMember = "Order_Details",
                        Dock = DockStyle.Fill},
                    new ComboBox() {
                        DataSource = orders, DisplayMember = "OrderID",
                        Dock = DockStyle.Top},
                    new ComboBox() {
                        DataSource = custs, DisplayMember = "CompanyName",
                        Dock = DockStyle.Top},                
                    (btn = new Button() {
                        Text = "Save", Dock = DockStyle.Bottom
                    }), // **edit here re textbox etc**
                    new TextBox {
                        DataBindings = {{"Text", orders, "ShipAddress"}},
                        Dock = DockStyle.Bottom
                    },
                    new Label {
                        DataBindings = {{"Text", custs, "ContactName"}},
                        Dock = DockStyle.Top
                    },
                    new Label {
                        DataBindings = {{"Text", orders, "RequiredDate"}},
                        Dock = DockStyle.Bottom
                    }
                }
            })
            {
                btn.Click += delegate {
                    form.Text = "Saving...";
                    ctx.SubmitChanges();
                    form.Text = "Saved";
                };
                Application.Run(form);
            }
        }
    }
    

    As an aside – note that the syntax:

    DataBindings = {{"Text", orders, "ShipAddress"}}
    

    Is equivalent to:

    someTextBox.DataBindings.Add("Text", orders, "ShipAddress");
    

    (I only add this as it is a common question)

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

Sidebar

Related Questions

This might sound like a little bit of a crazy question, but how can
I'm going through a Fortran code, and one bit has me a little puzzled.
A little bit confusion about some data structure in Python. Could any expert give
I'm doing a little bit of work on a horrid piece of software built
I'm having a little bit of a problem scaling my images to a properly
I've read a little bit about unit testing and was wondering how YOU unit
I'm having a little bit of trouble making a sticky form that will remember
Stuggling a little bit with the RegEx, I've got 4 codes in a string
I'm having a little bit of trouble understanding what the problem is here. I
I've been using PostgreSQL a little bit lately, and one of the things that

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.