By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,323 Members | 1,291 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,323 IT Pros & Developers. It's quick & easy.

Inherited Form/controls: controls copied, not inherited

P: n/a

I'm running into problems with VisualStudio.NET2003 and Windows
Forms inheritance. It _feels_ like a bug, but it could just as well
be a misunderstanding on my part regarding how the VS Designer
handles inheritance.


OS Name Microsoft Windows 2000 Professional
Version 5.0.2195 Service Pack 4 Build 2195
Microsoft Visual C# .NET
Microsoft Development Environment 2003 Version 7.1.3088
Microsoft .NET Framework 1.1 Version 1.1.4322


I'm building a single .EXE file with... er, "a number" of classes,
the Forms part of which looks like this:

PgtForm Your basic Form
+---frmStarttUp Startup window, menu, etc.
+---PgtDbEditForm Form with buttons for database edits
+---frmDbEdit1 Edit screen 1
+---frmDbEdit2 Edit screen 2

Sine all the code is int he one .EXE file, I'm using that as the
source for my inheritance (Project/AddInheritedForm...).

(NB: Someone is really missing out on a wonderful PhD thesis
dealing with the spontaneous generation of classes in OO software.
These suckers breed faster than a pair of bunnies! <grin>)

I've been trying to stomp out sporadic appearances of the following
error message when opening an inherited form in [Design] view:

Microsoft Development Environment
(X) The following exception has occurred:
Error: ArgumentException: This would cause two bindings in the
collection to bind to the same property.
Parameter name: binding.

I'd like to get rid of these because (a) error messages worry me,
and (b) the textbox and label colors are messed up in the form that
appears in [Design] view.


In the process of chasing these errors as they occur, I've
discovered that _sometimes_ (but not always) the VS Designer
propagates the actual code for control definitions for Form class
FormA downward in the inheriting Form class FormB.

This is a problem, because if I move a control around or resize it
on (say) PgtDbEditForm, I had expected that a change would
automatically propagate downward to (say) frmDbEdit1. If the
Designer _copies_ the C# code defining the control, rather than
simply using inheritance, the copied code acts to override the

That is, if I have a control txtBox1 in PgtDbEditForm and create a
new Form Form1 which inherits from PgtDbEditForm (via my .EXE file),
sometimes I get the complete definition for txtBox1 appearing in

If once this has occurred, I do the following:

- Close (e.g.) Form1[Design]
- Open Form1.cs
- Open up the sacrosanct No-user-servicable-components
"Designer generated code" section of Form1, and
- Delete the copied control definitions
- Close Form1.cs
- Open Form1[Design]
- Close Form1[Design]

when I re-open Form1.cs, the Designer (or some portion of VS) has
readded entries for the inherited controls, but only the ctl.Name

What are the rules here? I know, for example, that accidentally
clicking on a button in [Design] mode can trigger code generation,
but what controls when control inheritance becomes control
definition copying?

My workaround for now involves stomping on generated code (deleting
the control definitions in the inheriting form). This seems to
work, but I'm not really comfortable with it. Any suggestions will
be appreciated.

On a related note, in searching for an explanation for the original
error I did run across MS Article 821536, but it describes a hotfix
for a slightly different message appearing when inheriting from
Windows Forms containing DataSets. In my case I've moved all the
database access code into a separate class (although there are
occasional references to the one DataSet in this class).

Any clues or hints will be appreciated.
Frank McKenney, McKenney Associates
Richmond, Virginia / (804) 320-4887
Munged E-mail: frank uscore mckenney ayut minds pring dawt cahm (y'all)
Totalitarianism is the crushing of ordinary, intractable, human
reality by a political idea.
-- David Horowitz / The Politics of Bad Faith
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.