Child list for field Custom object cannot be created in DataGridView

Posted By  RRaveen On 30 Apr 2010 22:04:57
emailbookmarkadd commentsprint
No of Views:2224
Bookmarked:0 times
Votes:0 times

The Problem

When we are bind list of collection custom object in windows form DataGridView, this error occurred "Child list for field '' cannot be created".

 

Error Code Snippet

To reproduce this problem, just create a simple windows form application with datagrid and add a column , then create a custom object. in my sample i have created "TagInfo", then  you will create List  with custom object taginfo.below code,

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SampleError
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            List<TagInfo> collectionInfo = new List<TagInfo>();
            collectionInfo.Add(new TagInfo("Tag1", "Tag1"));
            collectionInfo.Add(new TagInfo("Tag2", "Tag2"));
            collectionInfo.Add(new TagInfo("Tag3", "Tag3"));
            collectionInfo.Add(new TagInfo("Tag4", "Tag4"));
            collectionInfo.Add(new TagInfo("Tag5", "Tag5"));
            
           

        }
    }
}

 

Then i have try to bind custom list to datagrid under the form load , liks using following code

this.dataGridView1.DataSource = collectionInfo;
this.dataGridView1.DataMember = "TagInfo";

The application throw exception "Child list for field TagInfo cannot be created.",the reason is we have given lsit of object as datasource.the DataGridView know what is object have to bind to gridview through the DataBindingManager in .NET Framework.So we dont need specify the object name when we are list to DataGridView.

Solutions

When we are bind to custom object collection to DataGridView through the list, just set the datasource only, dont need set the datamember.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SampleError
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            List<TagInfo> collectionInfo = new List<TagInfo>();
            collectionInfo.Add(new TagInfo("Tag1", "Tag1"));
            collectionInfo.Add(new TagInfo("Tag2", "Tag2"));
            collectionInfo.Add(new TagInfo("Tag3", "Tag3"));
            collectionInfo.Add(new TagInfo("Tag4", "Tag4"));
            collectionInfo.Add(new TagInfo("Tag5", "Tag5"));
            this.dataGridView1.DataSource = collectionInfo;
            

        }
    }
}

I hope this save your time and help to all.

Sign Up to vote for this article
Other popular Tips/Tricks
    In this tip, I will explain how to use the BigInteger in C# 4.0.The BigInteger is new data type in .NET 4.0.
    Published Date : 22/Sep/2011
    In this tips,I am going to discuss about two important thing about Split function of String class. Split function of the string class split the string in array of string.
    Published Date : 29/Jul/2011
    The Facebook is very popular and it has great support to other development Languages by Facebook SDKs.In this tips, I going to explain how to upload Videos to Facebook through C# with few lines of code.
    Published Date : 13/Jun/2011
    In this tip, i will share with you , how to format time HH:MM:SS from seconds in C#.
    Published Date : 25/Feb/2011
    Enums in dot net programming is a great facility and we all used it to increase code readability. In earlier version of .NET framework we don’t have any method anything that will check whether a value is assigned to it or not. In C# 4.0 we have new static method called HasFlag which will check that particular value is assigned or not.
    Published Date : 01/Jan/2011
Comments
By:RRaveenDate Of Posted:1/1/2011 2:10:46 AM
More about
Hi Swathi, Please give more details about your question.if i'm not wrong your face same problem what i have given solutions here.if not please post your problem in our messageboard. we will try to help. Thak you
By:swathiDate Of Posted:12/31/2010 3:11:51 AM
Child list for field app cannot be created.
please tell
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top