Employing a user control to workaround generic designer error

A

anthony

Again, as stated in previous posts I am new to C#, so explanations in
the form of a very introductory sense are appreciated. When trying to
view the designer after creating a generic class, I am confronted with
the following error:

Could not find type 'NAMESPACE.GENERIC_CLASS<TYPE>'. Please make sure
that the assembly that contains this type is referenced. If this type
is a part of your development project, make sure that the project has
been successfully built.

I have heard that UserControls can be employed as a workaround
solution to this issue. In any event, I was wondering what their
purpose was, and how/why they are employed. Any examples would be
very much appreciated. I understand that this is a known issue, but
also that it is an issue that can be worked around. Thank you in
advance for your assistance!


-Anthony
 
P

Peter Duniho

Again, as stated in previous posts I am new to C#, so explanations in
the form of a very introductory sense are appreciated. When trying to
view the designer after creating a generic class, I am confronted with
the following error:

Could not find type 'NAMESPACE.GENERIC_CLASS<TYPE>'. Please make sure
that the assembly that contains this type is referenced. If this type
is a part of your development project, make sure that the project has
been successfully built.

As a newbie, you should take a look at these links:
http://www.yoda.arachsys.com/csharp/complete.html
http://www.yoda.arachsys.com/csharp/incomplete.html
http://sscce.org/ (some Java-centric stuff, but mostly applicable to any
programming questions)

They contain important advice regarding how to ask an effective,
answerable question. In particular, the great importance and usefulness
of providing a concise-but-complete code example that reliably reproduces,
demonstrates, or otherwise illustrates the problem.
I have heard that UserControls can be employed as a workaround
solution to this issue.

Without a code example, we have no way to know what the "issue" is. The
error you quote seems to be self-explanatory: you are attempted to use
some type that is apparently unavailable at the time the component
(presumably the Designer) is attempting to use it.

This may yet again come down to you inappropriately modifying the
*.Designer.cs file, or it could be something else. If it's the former,
then the solution is clear: don't modify the *.Designer.cs file. Only the
Designer itself should be doing that. If it's something else, then you
need to provide more context.

As for the "UserControl" class itself...
In any event, I was wondering what their
purpose was, and how/why they are employed. Any examples would be
very much appreciated.

I'm sure Google can turn up a number of examples. But, the basic idea is:
the UserControl class is a specific kind of container class that the
Designer knows about, and which allows you to create a standalone,
editable UserControl-derived class within the Designer. It's primary use
is as a container, in which you place other controls in order to create a
new, user-defined aggregate control.

It's actually very much like a Form, except that it's intended to be used
inside a Form or other container, rather than being a top-level window
unto itself.
I understand that this is a known issue, but
also that it is an issue that can be worked around. Thank you in
advance for your assistance!

Again, we have no idea what "issue" you're describing, never mind whether
it's "known". Ideally, you will provide a concise-but-complete code
example that reliably demonstrates the problem. Barring that, it might be
helpful if you would at the very least provide references that describe
this "known issue"; on the assumption that your references simply describe
exactly the situation you're in (i.e. not just the error message), those
references could help us understand the problem too.

Pete
 
A

anthony

As a newbie, you should take a look at these links:http://www.yoda.arachsys.com/csharp.../csharp/incomplete.htmlhttp://sscce.org/(some Java-centric stuff, but mostly applicable to any  
programming questions)

They contain important advice regarding how to ask an effective,  
answerable question.  In particular, the great importance and usefulness  
of providing a concise-but-complete code example that reliably reproduces,  
demonstrates, or otherwise illustrates the problem.


Without a code example, we have no way to know what the "issue" is.  The  
error you quote seems to be self-explanatory: you are attempted to use  
some type that is apparently unavailable at the time the component  
(presumably the Designer) is attempting to use it.

This may yet again come down to you inappropriately modifying the  
*.Designer.cs file, or it could be something else.  If it's the former, 
then the solution is clear: don't modify the *.Designer.cs file.  Only the  
Designer itself should be doing that.  If it's something else, then you 
need to provide more context.

As for the "UserControl" class itself...


I'm sure Google can turn up a number of examples.  But, the basic idea is:  
the UserControl class is a specific kind of container class that the  
Designer knows about, and which allows you to create a standalone,  
editable UserControl-derived class within the Designer.  It's primary use  
is as a container, in which you place other controls in order to create a 
new, user-defined aggregate control.

It's actually very much like a Form, except that it's intended to be used 
inside a Form or other container, rather than being a top-level window  
unto itself.


Again, we have no idea what "issue" you're describing, never mind whether 
it's "known".  Ideally, you will provide a concise-but-complete code  
example that reliably demonstrates the problem.  Barring that, it mightbe  
helpful if you would at the very least provide references that describe  
this "known issue"; on the assumption that your references simply describe  
exactly the situation you're in (i.e. not just the error message), those  
references could help us understand the problem too.

Pete


After researching UserControls a bit, I am still unsure as to how they
have been applied as a workaround to this issue. Any suggestions are
greatly welcomed. And, my apologies for the lack of detail in my
initial explanation. Hopefully the code I have written below will
help guide towards a solution for anyone with experience on this
subject. Thanks in advance for your help everyone.

Below is the code that is producing the error:
Could not find type 'Example.NewObjComboBox'. Please make sure that
the assembly that contains this type is referenced. If this type is a
part of your development project, make sure that the project has been
successfully built.


--------------------Form.cs-CODE
SAMPLE------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Example {
public partial class Form1 : Form {
private NewObjComboBox<NewObj> comboBox1;

public Form1() {
InitializeComponent();
AddNewObjToItems();
}
public void AddNewObjToItems() {
NewObj cbo = new NewObj("1");
this.comboBox1.Items.Add(cbo);
this.Controls.Add(this.comboBox1);
this.comboBox1.ResumeLayout(false);
this.comboBox1.PerformLayout();
this.ResumeLayout(false);
}
}

public class NewObjComboBox<ClassType> : ComboBox {
private NewObjList<ClassType> m_list;

public NewObjComboBox() {
m_list = new NewObjList<ClassType>(base.Items);
}

new public NewObjList<ClassType> Items {
get { return m_list; }
}
}

public struct NewObj {
private string comboboxentry;

public NewObj(string c_box_var) {
comboboxentry = c_box_var;
}

public string ComboBoxEntry { get { return comboboxentry; } }

public override string ToString() {
return string.Format("{0}", ComboBoxEntry);
}
}

public class NewObjList<ClassType> //: IList<System.Object>
{
private ComboBox.ObjectCollection m_coll;

public NewObjList(ComboBox.ObjectCollection c) {
m_coll = c;
}

#region IList<object> Members
// Contains a list of members when interface implementation
tool is invoked
#endregion
}
-----------------------END OF Form.cs CODE
SAMPLE----------------------------------------

--------------------------------Form.Designer.cs InitializeComponent
method---CODE SAMPLE----------------------
private void InitializeComponent() {
this.comboBox1 = new NewObjComboBox<NewObj>();
this.comboBox1.SuspendLayout();
this.SuspendLayout();
//
// comboBox1
this.comboBox1.Anchor =
((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.comboBox1.DropDownWidth = 280;
this.comboBox1.Location = new System.Drawing.Point(21,
20);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(284, 21);
this.comboBox1.TabIndex = 0;
// Form1
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(338, 67);
this.Name = "Form1";
this.Text = "New ComboBox";
}

-----------------------------END OF Form.Designer.cs
InitializeComponent---CODE SAMPLE---------
 
A

anthony

As a newbie, you should take a look at these links:http://www.yoda.arachsys.com/csharp.../csharp/incomplete.htmlhttp://sscce.org/(some Java-centric stuff, but mostly applicable to any  
programming questions)

They contain important advice regarding how to ask an effective,  
answerable question.  In particular, the great importance and usefulness  
of providing a concise-but-complete code example that reliably reproduces,  
demonstrates, or otherwise illustrates the problem.


Without a code example, we have no way to know what the "issue" is.  The  
error you quote seems to be self-explanatory: you are attempted to use  
some type that is apparently unavailable at the time the component  
(presumably the Designer) is attempting to use it.

This may yet again come down to you inappropriately modifying the  
*.Designer.cs file, or it could be something else.  If it's the former, 
then the solution is clear: don't modify the *.Designer.cs file.  Only the  
Designer itself should be doing that.  If it's something else, then you 
need to provide more context.

As for the "UserControl" class itself...


I'm sure Google can turn up a number of examples.  But, the basic idea is:  
the UserControl class is a specific kind of container class that the  
Designer knows about, and which allows you to create a standalone,  
editable UserControl-derived class within the Designer.  It's primary use  
is as a container, in which you place other controls in order to create a 
new, user-defined aggregate control.

It's actually very much like a Form, except that it's intended to be used 
inside a Form or other container, rather than being a top-level window  
unto itself.


Again, we have no idea what "issue" you're describing, never mind whether 
it's "known".  Ideally, you will provide a concise-but-complete code  
example that reliably demonstrates the problem.  Barring that, it mightbe  
helpful if you would at the very least provide references that describe  
this "known issue"; on the assumption that your references simply describe  
exactly the situation you're in (i.e. not just the error message), those  
references could help us understand the problem too.

Pete

After researching UserControls a bit, I am still unsure as to how they
have been applied as a workaround to this issue. Any suggestions are
greatly welcomed. And, my apologies for the lack of detail in my
initial explanation. Hopefully the code I have written below will
help guide towards a solution for anyone with experience on this
subject. Thanks in advance for your help everyone.

Below is the code that is producing the error:
Could not find type 'Example.NewObjComboBox'. Please make sure that
the assembly that contains this type is referenced. If this type is a
part of your development project, make sure that the project has been
successfully built.

--------------------Form.cs-CODE
SAMPLE------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Example {
public partial class Form1 : Form {
private NewObjComboBox<NewObj> comboBox1;

public Form1() {
InitializeComponent();
AddNewObjToItems();
}
public void AddNewObjToItems() {
NewObj cbo = new NewObj("1");
this.comboBox1.Items.Add(cbo);
this.Controls.Add(this.comboBox1);
this.comboBox1.ResumeLayout(false);
this.comboBox1.PerformLayout();
this.ResumeLayout(false);
}
}

public class NewObjComboBox<ClassType> : ComboBox {
private NewObjList<ClassType> m_list;

public NewObjComboBox() {
m_list = new NewObjList<ClassType>(base.Items);
}

new public NewObjList<ClassType> Items {
get { return m_list; }
}
}

public struct NewObj {
private string comboboxentry;

public NewObj(string c_box_var) {
comboboxentry = c_box_var;
}

public string ComboBoxEntry { get { return comboboxentry; } }

public override string ToString() {
return string.Format("{0}", ComboBoxEntry);
}
}

public class NewObjList<ClassType> //: IList<System.Object>
{
private ComboBox.ObjectCollection m_coll;

public NewObjList(ComboBox.ObjectCollection c) {
m_coll = c;
}

#region IList<object> Members
// Contains a list of members when interface implementation
tool is invoked
#endregion
}
-----------------------END OF Form.cs CODE
SAMPLE----------------------------------------

--------------------------------Form.Designer.cs InitializeComponent
method---CODE SAMPLE----------------------
private void InitializeComponent() {
this.comboBox1 = new NewObjComboBox<NewObj>();
this.comboBox1.SuspendLayout();
this.SuspendLayout();
//
// comboBox1
this.comboBox1.DropDownWidth = 280;
this.comboBox1.Location = new System.Drawing.Point(20,
20);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(284, 21);
this.comboBox1.TabIndex = 0;
// Form1
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(338, 67);
this.Name = "Form1";
this.Text = "New ComboBox";
}

-----------------------------END OF Form.Designer.cs
InitializeComponent---CODE SAMPLE---------
 
P

Peter Duniho

After researching UserControls a bit, I am still unsure as to how they
have been applied as a workaround to this issue.

Well, something gave you the idea that they were. If you provide the
reference, maybe someone can explain it.

It's possible the suggestions you've seen are saying to create a
UserControl sub-class in which you explicitly add your generic-based class
as a parameterized concrete type explicitly created in the constructor of
the sub-class, hiding the generic aspect from the Designer and allowing it
to work.
Any suggestions are
greatly welcomed. And, my apologies for the lack of detail in my
initial explanation. Hopefully the code I have written below will
help guide towards a solution for anyone with experience on this
subject. Thanks in advance for your help everyone.

Below is the code that is producing the error:
Could not find type 'Example.NewObjComboBox'. Please make sure that
the assembly that contains this type is referenced. If this type is a
part of your development project, make sure that the project has been
successfully built.

Based on the code you posted, I suspect that once again you have been
modifying the *.Designer.cs file manually. Don't do that.

And yes, that means that you may not be able to use a generic type
directly as a control in the Designer.

I haven't had a chance to look closely at the scenario, but if you
_really_ feel a need to use a generic class as part of your control, you
should be able to define a generic base class, and then inherit that base
class as a parameterized concrete type in a new control class that will be
the actual one used in the Designer. Then use the Designer to add the
control to your form.

For what it's worth, if you are just learning .NET, mixing generics and
Designer code is probably not the best starting place. "Learn to walk
before trying to run" and all that. :)

Pete
 
A

anthony

Well, something gave you the idea that they were.  If you provide the  
reference, maybe someone can explain it.

It's possible the suggestions you've seen are saying to create a  
UserControl sub-class in which you explicitly add your generic-based class  
as a parameterized concrete type explicitly created in the constructor of 
the sub-class, hiding the generic aspect from the Designer and allowing it  
to work.



Based on the code you posted, I suspect that once again you have been  
modifying the *.Designer.cs file manually.  Don't do that.

And yes, that means that you may not be able to use a generic type  
directly as a control in the Designer.

I haven't had a chance to look closely at the scenario, but if you  
_really_ feel a need to use a generic class as part of your control, you  
should be able to define a generic base class, and then inherit that base 
class as a parameterized concrete type in a new control class that will be  
the actual one used in the Designer.  Then use the Designer to add the  
control to your form.

For what it's worth, if you are just learning .NET, mixing generics and  
Designer code is probably not the best starting place.  "Learn to walk  
before trying to run" and all that.  :)

Pete

The code that I have listed in the Designer.cs file contains some
commands (within InitializeComponent) that define the form. Since I
can:
a) only have one InitializeComponent method
b) not modify the Designer.cs file
c) not list these commands in an InitializeComponent method in the
form.cs file (as a result of condition a)
Where should the code exist that defines the form? By default the
InitializeComponent method is only defined in the Designer.cs file as
such:

*private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}

I wish to include commands that describe the form like those listed in
the previous post. I get that they cannot be included in the
Designer.cs file, and thus w/in the InitializeComponent method, so
where is the suggested place for these commands? Also, for reference,
here is a link that seems to go a good distance toward describing how
UserControls relate to this workaround
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/0c265543-d6f0-41f6-beeb-b89e0071c5c3.
From this forum I wish to get more understanding or background of what
a UserControl is and why it is necessary in the context of avoiding
this error. I believe elaborating a little more on the detail 'hiding
the generic aspect from the Designer' will bridge this gap. Perhaps
this explanation, along with its application to this problem (listed
in the link) will allow us without previous experience using
UserControls to both generally understand what they are, and how they
can be implemented to allow the use of Generics while avoiding this
Designer error. Thanks again in advance.
 
P

Peter Duniho

The code that I have listed in the Designer.cs file contains some
commands (within InitializeComponent) that define the form. Since I
can:
a) only have one InitializeComponent method
b) not modify the Designer.cs file
c) not list these commands in an InitializeComponent method in the
form.cs file (as a result of condition a)
Where should the code exist that defines the form?

As I and at least one other person explained the last time you posted a
question involving you editing the *.Designer.cs file, you should include
the code in the class constructor, immediately following the call to
InitializeComponent().
[...] Also, for reference,
here is a link that seems to go a good distance toward describing how
UserControls relate to this workaround
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/0c265543-d6f0-41f6-beeb-b89e0071c5c3.

The only reason "UserControl" is mentioned in that thread is that it's the
base class of the generic class the questioner is having problems with.
The suggested workarounds have nothing at all to do with the fact that the
base class is UserControl.
From this forum I wish to get more understanding or background of what
a UserControl is and why it is necessary in the context of avoiding
this error.

In my previous reply, I provided an explanation of what the UserControl
class is used for. As for why it's necessary in the context of avoiding
this error, it's not. You have misunderstood the message thread where it
seems to you that it is.
I believe elaborating a little more on the detail 'hiding
the generic aspect from the Designer' will bridge this gap.

The important thing to understand is that the Designer can't handle
generic classes at all. So, if you are to use a generic class in the
Designer, the generic aspect has to be deep enough in the inheritance
hierarchy that it doesn't have to deal with it.

This means at a minimum that the control class itself that you want to use
in the Designer cannot be generic. I believe -- and this is supported by
one of the messages in the topic thread for which you provided a URL
reference -- that the base class also must not be generic (if I recall
correctly, the Designer uses the base class to try to determine what
property values were modified by the control class, and so has to be able
to instantiate an instance of the base class as well...my memory on this
is vague though, so if it's important to you, you should look to another
reference to find out for sure).

Thus, my previous advice to inherit the generic class as a base type,
creating a non-generic type that _is_ usable in the Designer.
Perhaps
this explanation, along with its application to this problem (listed
in the link) will allow us without previous experience using
UserControls to both generally understand what they are, and how they
can be implemented to allow the use of Generics while avoiding this
Designer error. Thanks again in advance.

Forget UserControl. It has nothing at all to do with the issue you're
asking about.

Pete
 
A

anthony

The code that I have listed in the Designer.cs file contains some
commands (within InitializeComponent) that define the form.  Since I
can:
a) only have one InitializeComponent method
b) not modify the Designer.cs file
c) not list these commands in an InitializeComponent method in the
form.cs file (as a result of condition a)
Where should the code exist that defines the form?

As I and at least one other person explained the last time you posted a  
question involving you editing the *.Designer.cs file, you should include 
the code in the class constructor, immediately following the call to  
InitializeComponent().
[...] Also, for reference,
here is a link that seems to go a good distance toward describing how
UserControls relate to this workaround
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/0c26554.....

The only reason "UserControl" is mentioned in that thread is that it's the  
base class of the generic class the questioner is having problems with.  
The suggested workarounds have nothing at all to do with the fact that the  
base class is UserControl.
From this forum I wish to get more understanding or background of what
a UserControl is and why it is necessary in the context of avoiding
this error.

In my previous reply, I provided an explanation of what the UserControl  
class is used for.  As for why it's necessary in the context of avoiding  
this error, it's not.  You have misunderstood the message thread where it  
seems to you that it is.
I believe elaborating a little more on the detail 'hiding
the generic aspect from the Designer' will bridge this gap.

The important thing to understand is that the Designer can't handle  
generic classes at all.  So, if you are to use a generic class in the  
Designer, the generic aspect has to be deep enough in the inheritance  
hierarchy that it doesn't have to deal with it.

This means at a minimum that the control class itself that you want to use  
in the Designer cannot be generic.  I believe -- and this is supported by  
one of the messages in the topic thread for which you provided a URL  
reference -- that the base class also must not be generic (if I recall  
correctly, the Designer uses the base class to try to determine what  
property values were modified by the control class, and so has to be able 
to instantiate an instance of the base class as well...my memory on this  
is vague though, so if it's important to you, you should look to another  
reference to find out for sure).

Thus, my previous advice to inherit the generic class as a base type,  
creating a non-generic type that _is_ usable in the Designer.
Perhaps
this explanation, along with its application to this problem (listed
in the link) will allow us without previous experience using
UserControls to both generally understand what they are, and how they
can be implemented to allow the use of Generics while avoiding this
Designer error.  Thanks again in advance.

Forget UserControl.  It has nothing at all to do with the issue you're  
asking about.

Pete

Ok, so if the base class is used by the designer, then it sounds like
the generic class should at the very least be the "base base" class.
Or in other words:

class derived_class_1 : generic_class {...}
class derived_class_2 : derived_class_1 {...}

where derived_class_2 is the class defining the object used by the
designer? Also, thanks for the best practice tips on avoiding
directly coding in the designer. Regarding your initial suggestion,
'If it's the former, then the solution is clear: don't modify the
*.Designer.cs file. Only the Designer itself should be doing that.'
Can you submit a link on how to invoke the designer to begin applying
these modifications? Or, is it under 'Edit', 'View' or some other
easily accessible area in VS? Thanks again!

-Anthony
 
P

Peter Duniho

Ok, so if the base class is used by the designer, then it sounds like
the generic class should at the very least be the "base base" class.
Or in other words:

class derived_class_1 : generic_class {...}
class derived_class_2 : derived_class_1 {...}

where derived_class_2 is the class defining the object used by the
designer?

Yes, I believe that's required.

That assumes that having a generic (or generic-based) class that you can
manipulate in the Designer is really all that important. IMHO, custom
controls are great to know how to create and use when you need to, but the
existing controls are actually quite flexible. Often the best solution is
to not create a custom control class at all, never mind a generic one.
Also, thanks for the best practice tips on avoiding
directly coding in the designer. Regarding your initial suggestion,
'If it's the former, then the solution is clear: don't modify the
*.Designer.cs file. Only the Designer itself should be doing that.'
Can you submit a link on how to invoke the designer to begin applying
these modifications? Or, is it under 'Edit', 'View' or some other
easily accessible area in VS? Thanks again!

I don't understand the question. The point is to not edit the
*.Designer.cs file at all. What "modifications" is it that you feel you
need to know "how to invoke the designer to begin applying"?

Pete
 
A

anthony

Yes, I believe that's required.

That assumes that having a generic (or generic-based) class that you can  
manipulate in the Designer is really all that important.  IMHO, custom  
controls are great to know how to create and use when you need to, but the  
existing controls are actually quite flexible.  Often the best solutionis  
to not create a custom control class at all, never mind a generic one.


I don't understand the question.  The point is to not edit the  
*.Designer.cs file at all.  What "modifications" is it that you feel you  
need to know "how to invoke the designer to begin applying"?

Pete

When you say 'the Designer itself should be doing that', where 'doing
that' being 'modify the *.Designer.cs file', what is the Designer? It
sounds like something one uses to say grab some object and place it on
the form, which then causes modifications to be added to the
designer. I am just guessing, but would like to know what you are
referring to when you say 'the Designer' in the context of 'the
Designer itself should be doing that'. Again, without being familiar
my guess is just that, a guess. So, it is very likely I've
misunderstood. Thanks in advance for clarification!

-Anthony
 
P

Peter Duniho

When you say 'the Designer itself should be doing that', where 'doing
that' being 'modify the *.Designer.cs file', what is the Designer?

The Designer is the feature in Visual Studio that allows you to edit your
Form sub-class graphically. It is the thing that generates the error
you're asking about.
It sounds like something one uses to say grab some object and place it on
the form, which then causes modifications to be added to the
designer.

Not "to the designer", but to your Form sub-class _by_ the Designer.

When you add a Form sub-class to your project, two files are created: a
*.cs file with the same name as the class you've just added, and a
*.Designer.cs file also with that same name. When you double-click the
Form in the Solution Explorer, you get the graphical Designer UI. If you
right-click on the form in the Designer, or in the Solution Explorer,
there's the option to "View Code", which will take you to the *.cs file
where you're supposed to add code.

You can get to the *.Designer.cs file (and obviously you have figured out
how) by opening it directly from the Solution Explorer. And it can
sometimes be useful to inspect the code in that file, just to understand
what's going on "behind the scenes". But you shouldn't be actually
_changing_ that file. (Actually, there's at least one possible exception,
related to adding code to the Dispose() method, but even that there are
generally better ways to avoid having to do that, and that's not at all
related to what you've been working on).

Pete
 
P

Paul

Just read some more and I really do not know what you are trying to achieve.

Why are you mapping controls to wierd list objects, some sort of MVC / MVP?

Give us an idea of your goal and maybe we can point you in the right
direction.
 
A

anthony

Just read some more and I really do not know what you are trying to achieve.

Why are you mapping controls to wierd list objects, some sort of MVC / MVP?

Give us an idea of your goal and maybe we can point you in the right
direction.

Double wrapping the class worked for getting the combobox to appear in
the designer! My only issue now is when I add the combobox to my
Form's Controls set, the objects in the combobox's Items property are
not displaying. Before the call:

this.Controls.Add(<DOUBLE_WRAPPER_FOR_COMBOX>);

I have added a method to display the items in the combobox double-
wrapper, and these items are displaying fine. Why might they not be
added to the this.Controls with the statement listed above?

For reference, I was able to use the Toolbox in the Designer to drag
my double-wrapper for the combobox onto the form, and this created a
new object with the statement in the designer:

this.newObjComboWrprWrpr = new derived_class_2();

The method I referred to above simply displays each item in
'this.newObjComboWrprWrpr.Items' successfully, but when I add
'this.newObjComboWrprWrpr' to this.Controls as discussed above, the
items do not display at the end of the program. Any help is sincerely
appreciated!

-Anthony
 
P

Peter Duniho

[...] My only issue now is when I add the combobox to my
Form's Controls set, the objects in the combobox's Items property are
not displaying. Before the call:

this.Controls.Add(<DOUBLE_WRAPPER_FOR_COMBOX>);

I have added a method to display the items in the combobox double-
wrapper, and these items are displaying fine. Why might they not be
added to the this.Controls with the statement listed above?

I'd say it's because the statement you've included in your message isn't a
statement that would add items to a ComboBox (or something that inherits
ComboBox).

Your question is difficult to understand. You really should consider
posting a concise-but-complete code example that reliably demonstrates the
issue, along with a very specific step-by-step description of the steps
one needs to take, and the things one needs to observe, to understand the
problem.

Pete
 
A

anthony

[...] My only issue now is when I add the combobox to my
Form's Controls set, the objects in the combobox's Items property are
not displaying.  Before the call:
this.Controls.Add(<DOUBLE_WRAPPER_FOR_COMBOX>);

I have added a method to display the items in the combobox double-
wrapper, and these items are displaying fine.  Why might they not be
added to the this.Controls with the statement listed above?

I'd say it's because the statement you've included in your message isn't a  
statement that would add items to a ComboBox (or something that inherits  
ComboBox).

The issue is not getting items in the ComboBox. When I mentioned that
I was able to display the Items in the ComboBox with a function call,
that detail suggests that the Items are properly populated. That is
point A. Point B which I wish to get to is getting this populated
ComboBox onto the forms page. This is the:

this.Controls.Add(this.newObjComboWrprWrpr );

statement I spoke of above.
Your question is difficult to understand.  You really should consider  
posting a concise-but-complete code example that reliably demonstrates the  
issue, along with a very specific step-by-step description of the steps  
one needs to take, and the things one needs to observe, to understand the 
problem.

Pete

I'll try to pull the relevant details out of the code, but essentially
it all comes down to getting a double wrapped ComboBox onto a form.
It seems that if the other details are relevant, then they are all
relevant. And, posting a form, two wrapper classes (which contain
nothing, so this wouldn't be to verbose), a ComboBox class, and a List
class which overrides the ComboBox methods, and the Object class I've
defined to get into the ComboBox would be a lot to post. I'll try to
see if I can isolate and summarize the relevant code, however. So, to
summarize:

Point A: Items are populated in a double-wrapped ComboBox
Point B: ComboBox is added to Form

I am at A and I wish to get to B.
 
A

anthony

[...] My only issue now is when I add the combobox to my
Form's Controls set, the objects in the combobox's Items property are
not displaying.  Before the call:
this.Controls.Add(<DOUBLE_WRAPPER_FOR_COMBOX>);
I have added a method to display the items in the combobox double-
wrapper, and these items are displaying fine.  Why might they not be
added to the this.Controls with the statement listed above?
I'd say it's because the statement you've included in your message isn't a  
statement that would add items to a ComboBox (or something that inherits  
ComboBox).

The issue is not getting items in the ComboBox.  When I mentioned that
I was able to display the Items in the ComboBox with a function call,
that detail suggests that the Items are properly populated.  That is
point A.  Point B which I wish to get to is getting this populated
ComboBox onto the forms page.  This is the:

            this.Controls.Add(this.newObjComboWrprWrpr );

statement I spoke of above.
Your question is difficult to understand.  You really should consider 
posting a concise-but-complete code example that reliably demonstrates the  
issue, along with a very specific step-by-step description of the steps 
one needs to take, and the things one needs to observe, to understand the  
problem.

I'll try to pull the relevant details out of the code, but essentially
it all comes down to getting a double wrapped ComboBox onto a form.
It seems that if the other details are relevant, then they are all
relevant.  And, posting a form, two wrapper classes (which contain
nothing, so this wouldn't be to verbose), a ComboBox class, and a List
class which overrides the ComboBox methods, and the Object class I've
defined to get into the ComboBox would be a lot to post.  I'll try to
see if I can isolate and summarize the relevant code, however.  So, to
summarize:

Point A: Items are populated in a double-wrapped ComboBox
Point B: ComboBox is added to Form

I am at A and I wish to get to B.

In the designer.cs, the toolbox was implemented to drag the object ''
onto the form. Nothing else was done to this .cs. Below are the
details of Form1.cs (note that I have added the method that will show
the Items are populated in the double wrapper and can be displayed.
You will see that the ComboBox will appear on the form, just not
populated):

namespace Example
{
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
//
this.SuspendLayout();
this.newObjComWrprWrpr1.SuspendLayout();
this.Controls.Remove(this.newObjComWrprWrpr1);
//
// comboBox1
//
NewObj new_obj1 = new NewObj("1");
this.newObjComWrprWrpr1.Items.Add(new_obj1);
NewObj new_obj2 = new NewObj("2");
this.newObjComWrprWrpr1.Items.Add(new_obj2);
DisplayItems();
this.Controls.Add(this.newObjComWrprWrpr1);
this.newObjComWrprWrpr1.ResumeLayout(false);
this.newObjComWrprWrpr1.PerformLayout();
this.ResumeLayout(false);

this.newObjComWrprWrpr1.ResumeLayout(false);
this.newObjComWrprWrpr1.PerformLayout();
this.ResumeLayout(false);
}
void DisplayItems() {
int index = 0;
while (this.newObjComWrprWrpr1.Items.Count > index) {
MessageBox.Show(this.newObjComWrprWrpr1.Items
[index].ToString());
++index;
}
}
}

public partial class NewObjComWrprWrpr : NewObjComWrpr { }

public class NewObjComWrpr : NewObjComboBox<NewObj> { }

public class NewObjComboBox<ClassType> : ComboBox {
private NewObjList<ClassType> m_list;

public NewObjComboBox() {
m_list = new NewObjList<ClassType>(base.Items);
}

new public NewObjList<ClassType> Items {
get { return m_list; }
}
}

public struct NewObj {
private string comboboxentry;

public NewObj(string c_box_var) {
comboboxentry = c_box_var;
}

public string ComboBoxEntry { get { return comboboxentry; } }

public override string ToString() {
return string.Format("{0}", ComboBoxEntry);
}
}

public class NewObjList<ClassType> //: IList<System.Object>{
private ComboBox.ObjectCollection m_coll;

public NewObjList(ComboBox.ObjectCollection c) {
m_coll = c;
}

..
..
..
public ClassType this[int index]
{
get { return (ClassType)m_coll[index]; }
set { throw new NotImplementedException(); }
}
..
..
..
public void Add(ClassType item)
{
m_coll.Add(item);
}
..
..
..
public int Count
{
get { return m_coll.Count; }
}
..
..
..
}
 
P

Peter Duniho

[...] My only issue now is when I add the combobox to my
Form's Controls set, the objects in the combobox's Items property are
not displaying.  Before the call:
this.Controls.Add(<DOUBLE_WRAPPER_FOR_COMBOX>);

I have added a method to display the items in the combobox double-
wrapper, and these items are displaying fine.  Why might they not be
added to the this.Controls with the statement listed above?

I'd say it's because the statement you've included in your message
isn't a  
statement that would add items to a ComboBox (or something that
inherits  
ComboBox).

The issue is not getting items in the ComboBox.

You wrote "Why might they not be added...". The pronoun "they" must have
an antecedent, and the usual English rule is to look to the immediately
preceding noun, which in your post is "these items". The word "these"
itself has an antecedent, with the word "items" restricting "these" to
being something called "items". The only other "items" mentioned in that
paragraph are "the items in the combobox double-wrapper".

But, ComboBox items aren't the kind of thing one would expect to be added
via a call to "this.Controls.Add()".
When I mentioned that
I was able to display the Items in the ComboBox with a function call,
that detail suggests that the Items are properly populated.

No, it doesn't, not given everything else you wrote. See above for how
English-speaking people parse your paragraph (I don't know whether English
is your native language...if not, that could explain why your post doesn't
say what you seem to think it does).

All that saying "these items are displaying fine" does is confuse the
issue. But given the vague nature of your post, it's not event obviously
contradictory that items in the ComboBox "are displaying fine" and yet are
not "added to the this.Controls". After all, one would never expect items
_in_ a ComboBox to be found in the Controls collection; they aren't
controls.
[...]
I'll try to pull the relevant details out of the code, but essentially
it all comes down to getting a double wrapped ComboBox onto a form.
It seems that if the other details are relevant, then they are all
relevant. And, posting a form, two wrapper classes (which contain
nothing, so this wouldn't be to verbose), a ComboBox class, and a List
class which overrides the ComboBox methods, and the Object class I've
defined to get into the ComboBox would be a lot to post.

Create a code example that contains _nothing_ except the bare minimum to
demonstrate the problem. Make sure that code example can be compiled and
run without the addition of _anything_ to the source code. Whether it's
"a lot to post" or not doesn't matter. If that's really the minimum
amount of code required to reproduce the problem, so be it.
I'll try to
see if I can isolate and summarize the relevant code, however. So, to
summarize:

Point A: Items are populated in a double-wrapped ComboBox
Point B: ComboBox is added to Form

I am at A and I wish to get to B.

Again, your question is confusing. You already wrote that you are able to
succesfully drag your "double-wrapper for the combobox onto the form",
which necessarily places it visibly on the form. So I don't see how you
are not already "at B". Besides that, in your follow-up post, you seem to
state that the control _does_ appear on the form (i.e. "is added to
Form"), but it simply doesn't seem to display the items you want to
display. That is, you wrote "You will see that the ComboBox will appear
on the form, just not populated". (Of course, I won't "see" anything,
because the code example doesn't compile, never mind run. But that's what
your description seems to be saying).

As I wrote before: you really need to post a proper code example, one that
shows the minimum code required to reproduce the issue, but which can
still be compiled and executed without any additional code. Along with
that, you need to be VERY specific about exactly when you see the problem,
and how the problem is reproduced. It's not at all clear from your posts
whether you're concerned about display in the Designer, during run-time,
or both, and what it is you expect to happen.

Pete
 
P

Paul

Anthony,

Call me stupid but I still do not understand what your are trying to
achieve. From a use case perspective what are your goals.

1. You talk about adding controls from the designer but then give examples
of adding controls to the form.controls list dynamically. This confuses me!

2. You talk about double wrapping controls. What is this, Why and again what
are you trying to achieve.

It all seems overly complicated for a web application, Overdoing something
will inevitably lead to a maintenance nightmare going forward, so my advice
is pick your battles, and maybe review your goals.
 
A

anthony

Anthony,

Call me stupid but I still do not understand what your are trying to
achieve. From a use case perspective what are your goals.

1. You talk about adding controls from the designer but then give examples
of adding controls to the form.controls list dynamically. This confuses me!

2. You talk about double wrapping controls. What is this, Why and again what
are you trying to achieve.

It all seems overly complicated for a web application, Overdoing something
will inevitably lead to a maintenance nightmare going forward, so my advice
is pick your battles, and maybe review your goals.

Paul: I am trying to find a means of getting a generic ComboBox for
which any kind of object can be added to its Items collection to
appear in the Designer before Items are added, and appear at compile
time with the populated Items after they are added in the Form.cs. I
apologize for not clarifying this as a response to your last post.

Peter: It seems that you are taking my questions posted to this forum
in an unusually personal manner. Your sincerest responses to this
post have been very helpful and much appreciated. However, you have
grown increasingly hostile throughout this post to a point where you
are behaving in an unacceptable manner. When one runs the following
statement:
"See above for how English-speaking people parse your paragraph (I
don't know whether English is your native language..."
through any translator, the conclusion is that you are being offensive
and rude.

All: The DisplayItems function is showing 1, then 2 in a MessageBox,
so these Items which were added to the doubly wrapped ComboBox are in
fact in the ComboBox as Items. However when this ComboBox is added to
the form via the following statement:
this.Controls.Add(this.newObjComWrprWrpr1);
the doubly wrapped ComboBox appears on the form, but without the two
Items (1 & 2) that were displayed in the MessageBoxes via the
DisplayItems method. I am wondering why they are not displayed in the
doubly wrapped ComboBox.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top