"Can't create a child list" error message occurs when you open a form in Visual Studio .NET

BUG #: 3381 (Content Maintenance)
This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about how to obtain support for a Beta release, see the documentation that is included with the Beta product files, or check the Web location where you downloaded the release.

Symptoms

When you delete the table that is bound to a control form of the DataSet Schema and then save the project in Microsoft Visual Studio .NET, you may receive the following error message when you open the form in Design view:

Can't create a child list for field
TableName.

The controls that are added before the data bound control are deleted from the form by Visual Studio .NET, and you receive the following error message in the data bound control:

System.ArgumentException: Can't create a child list for field
TableName.

Cause

In Windows Form Designer-generated code, the controls are displayed on the form when the Control array is added to the Controls collection of the form. The last control that is added to the form has the index 0 in the Control array, the first control has the highest index, and then the other controls. When the XML Schema is changed, the data bound control raises an error and the controls that were added to the form before the data bound control are removed from the array because the controls are after the data bound control in the Control array. Therefore, the controls are not added to the Controls collection of the form and are not displayed.

Workaround

To work around this problem, do not save the project after you delete the table from the DataSet Schema file. Open the Windows Form, and then set the DataSource property and the DisplayMember property of the bound control to none. If the controls are lost, you can add controls manually to the Controls collection of Form1. To do this for the sample application that is used in the "More information" section of this article, follow these steps:
  1. Right-click Form1, and then click
    View Code.
  2. In the InitializeComponent procedure of the Windows Form Designer generated code region, locate the following statement in the Form1 code:

    Microsoft Visual Basic .NET code
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox2, Me.TextBox1, Me.ListBox1})
    Microsoft Visual C# .NET code
    this.Controls.AddRange(new System.Windows.Forms.Control[] {this.textBox2,this.textBox1,this.listBox1});
  3. Add the name of the missing controls:

    Visual Basic .NET code
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox2, Me.TextBox1, Me.Button2,Me.Button1,Me.ListBox1})
    Visual C# .NET code
    this.Controls.AddRange(new System.Windows.Forms.Control[] {  this.textBox2,this.textBox1,this.button1,this.button2,  this.listBox1});

Status

This behavior is by design.

More Information

Steps to reproduce the behavior

  1. In Visual Studio .NET, create a new Windows Application by using Visual Basic .NET or Visual C# .NET. By default, Form1 is created.
  2. Create a new data connection. To do this, follow these steps:
    1. On the View menu, click
      Server Explorer.
    2. In Server Explorer, right-click
      Data Connections, and then click Add Connection.
    3. In Data Link Properties window, click the Connection tab.
    4. Type the name of the local computer that is running SQL Server in the Select or enter a server name box, and then click NorthWind in the Select the database on the server list.
  3. In the Toolbox, click the
    Data tab, and then add a SqlConnectioncontrol to Form1.
  4. Right-click the SqlConnection1 control, and then click Properties.
  5. In the Properties window, set the value of the ConnectionString property to the data connection that was created in step 2.
  6. Add a SqlDataAdapter control to Form1. In the Data Adapter Configuration Wizard, click Next
    three times, and then type the following SQL statement:
    select * from Customers
  7. Click Next, and then click
    Finish to close the wizard.
  8. Right-click SqlDataAdapter1, and then click Generate Dataset. Click OK.
  9. Finish adding controls to the form. To do this, follow these steps:
    1. Add two Button controls to Form1.
    2. Add a ListBox control to Form1.
    3. Right-click ListBox1, and then click
      Properties.
    4. In Properties window, set the value of the DataSource property to DataSet11, and then set the value of the DisplayMember property to
      Customers.CustomerID.
    5. Add two TextBox controls to Form1.
  10. On the View menu, click Solution Explorer.
  11. In Solution Explorer, double-click
    DataSet1.xsd.
  12. Right-click the Customers table, and then click Delete.
  13. On the File menu, click Save All to save the project.
  14. Double-click Form1.vb to open Form1. The error message that was mentioned in the "Symptoms" section of this article appears and all the controls that were added to Form1 before ListBox1 was added are removed.

References

For more information, visit the following Microsoft Developer Network (MSDN) Web site:
Propriedades

ID do Artigo: 816799 - Última Revisão: 23 de mar de 2009 - Revisão: 1

Comentários