473,385 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

A circular control reference has been made

I try this code to make controls at run time.

I got this bug "A circular control reference has been made. A control cannot be owned by or parented to itself".

How to resolve this?



Expand|Select|Wrap|Line Numbers
  1. class control
  2.     {
  3.         public System.Windows.Forms.TextBox[] textbox;
  4.         public System.Windows.Forms.Label[] label;
  5.         //public System.Windows.Forms.Button buton1;
  6.         //public System.Windows.Forms.Button buton2;
  7.         public int t;
  8.  
  9.         public int k2 = 50;
  10.         public void ctrl()
  11.         {
  12.             textbox = new TextBox[t];
  13.             label = new Label[t];
  14.             for (int i = 0; i < t; i++)
  15.             {
  16.  
  17.                 textbox[i] = new TextBox();
  18.                 textbox[i].Name = "TextBox" + i.ToString();
  19.                 textbox[i].Left =200;
  20.                 textbox[i].Top = k2;
  21.                 textbox[i].Size = new System.Drawing.Size(100, 20);
  22.                 textbox[i].TabIndex = i;
  23.                 textbox[i].Visible = true;
  24.                 textbox[i].Text = " Enter the item" + i.ToString();
  25.                 this.textbox[i].Controls.Add(this.textbox[i]);
  26.  
  27.                 label[i] = new Label();
  28.                 label[i].Name = "Label" + i.ToString();
  29.                 label[i].Location = new System.Drawing.Point(300, k2);   
  30.                 label[i].Size = new System.Drawing.Size(150, 20);
  31.                 label[i].Visible = true;
  32.                 label[i].TabIndex = 1;
  33.                 label[i].AutoSize = true;
  34.                 label[i].Text = "Item " + i.ToString() + ":";
  35.                 this.label[i].Controls.Add(this.label[i]);
  36.                 k2 += 50;
  37.             }
  38.     }
Please help me to resolve this.
Mar 22 '12 #1
2 6580
r035198x
13,262 8TB
What are you trying to accomplish with the line:
this.textbox[i].Controls.Add(this.textbox[i]); ?
Mar 22 '12 #2
Frinavale
9,735 Expert Mod 8TB
r035198x found the problem.

Line 25 in the code you originally posted is adding a TextBox to the same TextBox's controls. This doesn't make any sense to people or the compiler.

If this is a control that contains other controls, then maybe your code on line 25 should be:

this.Controls.Add(this.textbox[i]);

Also, line 35 should be changed to:
this.Controls.Add(this.label[i]);

-Frinny
Mar 22 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ColinWard | last post by:
Hi again. I am trying to figure out how to make sure that a value has been selected from a combobox on a form. I have tried using isnull(comboboxname.text) and isempty(comboboxname.text)and...
7
by: vindaloo1 | last post by:
I'm using Access 2000 and I have a main form and a subform. When a control on the subform is updated I am trying to update a control on the mainform. But instead of updating the control on the...
1
by: Brian | last post by:
I have created two forms Selector and Circuit. Selector is an unbound form where fields are populated and there is a command button which opens Circuit and displays information based on the input...
1
by: Jon Stranger | last post by:
I am trying to build a custom web control based on DataGrid using VS.NET Standard Edition and have a problem referencing the Columns collection. The control has been built in a separate VS.NET...
5
by: Bob | last post by:
Using Vs 2005 and Vb.NET I want to give users a message asking if they're sure they want to close the form if they had made changes to the underlying data. How do I detect if changes had been made...
2
by: Neil | last post by:
I need to be able to determine if a user has actually made a change when on either the edititem or insertitem templates of a formview control. Is there a standard way of handling this to prevent...
2
by: Alex Maghen | last post by:
I need to be able to get a reference to a Control on an ASPX Page by the exact ID that I gave that control at Design-Time. Let's say I created an ASPX that had a control: <asp:TextBox...
3
by: Boris | last post by:
I was making a part of an application more and more generic when I suddenly ended up with code like this: template <class T> struct MenuItems { T &m; MenuItems(T &m); }; template <class T>
0
by: JasenC | last post by:
I've just upgraded from VS 2003 to VS 2005 and I've downloaded the latest service pack. However when I try to add a button to my form in design mode I keep getting this error. "A circular...
3
by: Andrew Hallett | last post by:
I'm trying to design a query in Access 2007 that will select clinicians based upon a list of desired counties and specialties. The query receives its parameters from a form where the searcher may...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.