'Circular reference' error but can't find such an error in the code.

  • Thread starter Thread starter Richard Lewis Haggard
  • Start date Start date
R

Richard Lewis Haggard

I've created in form that has tab controls that contain tab controls that
host user controls on each tab page. It compiles and runs just fine but the
designer view fails with a "A circular control reference has been made. A
control cannot be owned or parented to itself." Additionally, there are a
lot of "Operation is not valid due to the current state of the object."
errors. However, when I look at the code, I do not see any place in the code
that looks like it could be assigning a circular reference. None of the
lines like 'tabMain.Controls.Add(xxx)' are trying to add themselves to the
control collection and all of the relationships look proper. Is there some
other way that this error can be generated?
 
Richard Lewis Haggard said:
I've created in form that has tab controls that contain tab controls that
host user controls on each tab page.

Tab controls on tab controls. Sounds like a bad user interface.

Michael
 
I suggest putting breakpoint & switching to design view
This might lead you to the code - which results in this error

HTH
Kalpesh
 
Hi,

Michael C said:
Tab controls on tab controls. Sounds like a bad user interface.

I hav one such construction, in a PPC app not enough space and lot of info
to display :(
 
Break on a break point in non-executing code? I was unaware that this was
possible. I put a break on every single function but no break was observed
when viewing in design mode.
 
Richard,

I didnt try that out.
However, I thought that the controls that you drop on the form at
design time generate code in the background.

Hence, when you switch back & forth - it might run the code to set
properties
Sorry for the inconvenience.

Kalpesh
 
Normally, I'd agree with you but in this case, the UI works surprisingly
well for its designated purpose.

Target audience:
internal developers

Goals:
Blindingly obvious to use
Exceedingly easy to extend
UI elements for each test are modular.
Handlers for each test's UI events are encapsulated in separate classes

A nested pair of tabs working in conjunction with user controls satisfy the
design goals - with the one obvious exception that there is some non-obvious
circular reference. If someone has an alternative architecture, I'd be
delighted to hear of it.

Oddly, the project compiles and runs just fine. It is only the form designer
issue that is a problem.
--
"On being told by Rumsfield that three Brazilian soldiers had died in Iraq,
President Bush froze, turned white and, after a pause, asked, "Just exactly
how many is a bazillion?"
Richard Lewis Haggard
www.Haggard-And-Associates.com
 
Fire up another instance of VS and load your project. Place your
breakpoints and then use the Tools menu to attach to the other
devenv.exe. Then you can debug when it goes into design mode.
 
I think that I've found the problem.

The main form had a status label which was intended to display test results.
In order to provide access to this label, I made it public and passed in a
reference to the main form to each of the user controls after that user
control had been created. If I remove the lines that do this for each of the
user controls and then do a solution rebuild (not a project rebuild), then
the design time display of the main form works.

Oddly, I can put the line that passes the main form reference to the user
control classes back in and the design time still displays after each build.
It is only a solution rebuild that will trigger the error condition again
and only a solution rebuild that will remove the error condition.

So, in conclusion, it may be that the user control's form member that was
holding a reference to the parent form was the problem.
 
Back
Top