.NET Framework - How can i use the editor attribute?
Asked By Sa
22-Jun-07 04:36 AM

Hello there,
Please I need help on how to use the editor attribute. I am trying to learn
how to create User Controls? I created a UserControl using VB.NET. It
Contain a TreeView control and I want to expose the TreeView nodes
collection
and support the design-time environment by using the Editor attribute. But
when I tried to use it I get the following error message:
(value of type 'System.Windows.Forms.TreeNodeCollection' cannot be converted
to '1-dimensional array of System.Windows.Forms.TreeNodeCollection').
The editor attribute takes two parameters
(Typename as string, base typename as string)
(Typename as string, base typename as system.Type)
(Typename as system.type, base typename as system.Type)
I could not understand how to use these parameters?
I tried for many times during the last five days to resolve the problem but
I could not do it. Please someone help me and tell me how to write the
Editor attribute the correct way? What exactly the types that I should pass
to the editor attribute in my case?
The following is my tree node collection property:
Description("Gets the TreeView Nodes collection"), _
Category("TreeView"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
Editor(System.Windows.Forms.TreeNodeCollection,
System.Windows.Forms.TreeNodeCollection)> _
Public ReadOnly Property Nodes() As TreeNodeCollection()
Get
Return Me.tvTreeView.Nodes <------ (the error appears in this
line)
End Get
End Property
Thank you.
Kevin Spencer replied...
A Design-Time Editor is a special Control that is used to set properties at
Design-Time. Desitn-Time Editors inherit System.Drawing.Design.UITypeEditor.
There is no built-in Editor for a TreeNodeCollection, so you have to create
one. Here's a good starting point for learning how:
http://msdn2.microsoft.com/en-us/library/ms171838.aspx
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
Sa replied...

Dear Kevin,
Why in C# i can pass TreeNodeCollection type to the Editor Attribute but in
VB I get the following error:
(value of type 'System.Windows.Forms.TreeNodeCollection' cannot be converted
to '1-dimensional array of System.Windows.Forms.TreeNodeCollection').
Is the implementation of Editor attribute in c# different then VB.?
C# Codes:
[Browsable(true), _Description("Gets the TreeView Nodes collection"),
Category("TreeView"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor(typeof(TreeNodeCollection), typeof(TreeNodeCollection))]
public TreeNodeCollection Nodes
{
get
{
return this.tvTreeView.Nodes;
}
}
VB Codes:
Description("Gets the TreeView Nodes collection"), _
Category("TreeView"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
EditorAttribute(GetType(TreeNodeCollection), _
GetType(TreeNodeCollection))> _
Public ReadOnly Property Nodes() As TreeNodeCollection()
Get
Return Me.tvTreeView.Nodes
End Get
End Property
Thank you.
Kevin Spencer replied...
If you want to add elements to a TreeNodeCollection, you will need to
implement a Modal Dialog Editor, yes, if that's what you're asking.
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
Kevin Spencer replied...
Hi Sam,
A TreeNodeCollection is not a UITypeEditor class. A TreeNodeCollection is
just a Collection of TreeNode instances. I thought you were clear on that
issue. You need to implement and reference a UITypeEditor class, and
reference that in the Editor attribute. As to why you got the specific
exception message, I have no idea. The code you wrote was bound to throw an
exception, but as to where exactly in the Framework processing chain
something barfed and why iot barfed at that specific point, or what it was
trying to do at that point, I can't say.
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
NET Framework TreeNodeCollection eines UserControls zuweisen Hi, Ich habe hin- und herprobiert, aber der Compiler mag mal wieder ihm vorsetze 8- / Alles was ich erreichen m = F6chte, ist die "Freigabe" der Nodes eines TreeView, das sich auf meinem UserControl befindet, so da = DF ich den Baum mit myControl.Nodes ansprechen und (auch zur Designzeit auf meinem Blog unter > www.mariofraiss.com gerne ;-) Wie = FCbergebe ich diese "meineNodes" an das UserControl? Array, List? Und es ist wirklich unm = F6glich die Nodes so "durchzuschleifen", da = DF man konfigurieren kann? Michaela Erst Fragen bestellen und dann nicht antworten, tststs ;-) Was soll denn das UserControl damit? Ich dachte, du willst die Collection nur durchreichen? hmm, mit dem zweiten Teil kann System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } [Browsable(true), Description("TreeNodeCollection durchreichen"), Category("TreeView"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(typeof(TreeNodeCollection), typeof(TreeNodeCollection))] public TreeNodeCollection Nodes { get { return this.treeView1
editor attribute. I am trying to learn how to create User Controls. I created a UserControl using VB.NET that contine a treeview control. I want to expose the treeview nodes collection and support the design-time environment by using the Editor attribute. But when to use it I get the following error message: (value of type 'System.Windows.Forms.TreeNodeCollection' cannot be converted to '1-dimensional array of System.Windows.Forms.TreeNodeCollection') . The editor attribute takes two parameters (Typename as string, base typename as string) (Typename as attribute the correct way. The following is my tree node collection property: Description("Gets the TreeView Nodes collection"), _ Category("TreeView"), _ DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _ Editor(System.Windows.Forms.TreeNodeCollection, System.Windows.Forms.TreeNodeCollection)> _ Public ReadOnly