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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:53:10+00:00 2026-05-22T12:53:10+00:00

Would someone kindly assist me with the following? I have two DataGridView objects that

  • 0

Would someone kindly assist me with the following? I have two DataGridView objects that each display a DataTable, where the two datatables are related with the following code:

DataSet dSet = new DataSet();
DataTable ParentList = ListToDataTable(_listOfAllAlbumObjects);
DataTable ChildList = ListToDataTable(_listOfAllTrackObjects);
dSet.Tables.AddRange(new DataTable[]{ParentList, ChildList});
DataColumn parentRelationColumn = ParentList.Columns["AlbumId"];
DataColumn childRelationColumn = ChildList.Columns["AlbumId"];
dSet.Relations.Add("ParentToChild", parentRelationColumn, childRelationColumn);
ParentDataGridView.DataSource = dSet;
ParentDataGridView.DataMember = "ParentList";
ChildDataGridView.DataSource = ???;
ChildDataGridView.DataMember = "ParentToChild";

Both DataTables are actually List<> converted to DataTables with the following:`

    public static DataTable ListToDataTable<T>( IList<T> data)
    {
              var props = TypeDescriptor.GetProperties(typeof(T));
              var table = new DataTable();
              for (var i = 0; i < props.Count; i++)
              {
                  PropertyDescriptor prop = props[i];
                  table.Columns.Add(prop.Name, prop.PropertyType);
              }
              var values = new object[props.Count];
              foreach (T item in data)
              {
                  for (int i = 0; i < values.Length; i++) 
                  { values[i] = props[i].GetValue(item); }
                  table.Rows.Add(values);
              }
              return table;
          }

Initially it appears that the each DataGridView displays the data appropriately; however the child DataGridView does not update with any change of record in the parent DataGridView.

I see that the tables need to be interconnected through the binding-source; however I don’t believe there is a true binding-source here.

Could someone please steer me in the right direction? Thanks.

  • 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-22T12:53:12+00:00Added an answer on May 22, 2026 at 12:53 pm

    There’s an MSDN article showing what you want to do:

    How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls

    Here’s how this might work for you:

    Either through the designer or through code add two BindingSources to your project: parentBindingSource and childBindingSource. Then try this in place of the code you have.

    // Associate your BSs with your DGVs.
    ParentDataGridView.DataSource = parentBindingSource;
    ChildDataGridView.DataSource = childBindingSource;
    
    // (Most of) your code here:
    DataSet dSet = new DataSet();
    DataTable ParentList = ListToDataTable(_listOfAllAlbumObjects);
    DataTable ChildList = ListToDataTable(_listOfAllTrackObjects);
    dSet.Tables.AddRange(new DataTable[]{ParentList, ChildList});
    DataColumn parentRelationColumn = ParentList.Columns["AlbumId"];
    DataColumn childRelationColumn = ChildList.Columns["AlbumId"];
    dSet.Relations.Add("ParentToChild", parentRelationColumn, childRelationColumn);
    
    // Let's name this DT to make clear what we're referencing later on.
    ParentList.TableName = "ParentListDT";
    
    // Rather than set the data properties on your DGVs, set them in your BindingSources.
    parentBindingSource.DataSource = dSet;
    parentBindingSource.DataMember = "ParentListDT";
    
    childBindingSource.DataSource = parentBindingSource;
    childBindingSource.DataMember = "ParentToChild";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two divs. One of them contains an input field the other a
I have 2 tables: Person and Item. I just created a new column in
In terms of expansion of my knowledge, I would like to try to make
I'm having a problem. I'm using jquery.lightbox-0.5 to display images and everything works fine
I have many small java programs running in crons in my server. I have
Can someone explain the concepts of IPoIB and TCP over InfiniBand? I understand the
I would like to embed a css file using [Embed(source = 'mystyle.css', mimeType =
We just came across this in an old production stored proc (there is a
The code below works exactly as I want it to in my perl script.

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.