473,395 Members | 1,473 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,395 software developers and data experts.

Implementing a custom control with a typed collection for use at design time.

I am having a problem with the Visual Basic property collection editor .

I have created a Custom Type

Expand|Select|Wrap|Line Numbers
  1. Public Class Field
  2.          Private Item As Integer
  3.         Private Name As String = "FieldName"
  4.  
  5.           Public Property FieldName() As String
  6.             Get
  7.                 Return Name
  8.             End Get
  9.             Set(ByVal value As String)
  10.                 Name = value
  11.             End Set
  12.         End Property
  13. End Class
  14.  
And a collection

Expand|Select|Wrap|Line Numbers
  1. Public Class Fields
  2.         Inherits CollectionBase
  3.  
  4.         Default Public Property Item(ByVal Index As Integer) As Field
  5.             Get
  6.                 Return CType(List.Item(Index), Field)
  7.             End Get
  8.             Set(ByVal value As Field)
  9.                 List.Item(Index) = value
  10.             End Set
  11.         End Property
  12.         Public Sub Add(ByVal Item As Field)
  13.             If List.Count = 0 Then
  14.                 List.Add(Item)
  15.             Else
  16.                 For i = 0 To List.Count - 1
  17.                     Dim myField As New Field
  18.                     myField = List(i)
  19.                     If myField.FieldName = Item.FieldName Then
  20.                         Item.FieldName += "1"
  21.                     End If
  22.                 Next
  23.                 List.Add(Item)
  24.             End If
  25.         End Sub
  26.  
  27.     End Class
  28.  
My property declaration uses an instance of the collection:

Expand|Select|Wrap|Line Numbers
  1. Public TableFields As New Fields
  2.  
  3.     Public Property Evarus_Fields() As Fields
  4.         Get
  5.             Return TableFields
  6.         End Get
  7.         Set(ByVal value As Fields)
  8.             TableFields = value
  9.         End Set
  10.     End Property
  11.  

In the designer I am able to access my class and save the items in the collection, but then entries in the designer are incorrect. The created entry actually causes a syntax error on the command ‘New’

Expand|Select|Wrap|Line Numbers
  1. Field1.FieldName = "ColumnA"
  2. New ProjectName.ControlName.Fields.Add(Field1)
  3.  
Modification to the created codes as follows (reference the control instance and the instantiated collection) cures the syntax errors and works as desired.

Expand|Select|Wrap|Line Numbers
  1. Field1.FieldName = "ColumnA"
  2. ControlInstanceName.TableFields.Add(Field1)
  3.  
Any ideas about what my coding error is?
Oct 14 '10 #1

✓ answered by David Gluth

I have resolved my issue.
I needed to provide a “customized” collection editor for my typed class (Field).

Expand|Select|Wrap|Line Numbers
  1. Public Class FieldCollection
  2.         Inherits CollectionEditor
  3.         Public Sub New()
  4.             MyBase.New(GetType(List(Of Field)))
  5.         End Sub
  6.     End Class
  7.  
And then supplied an attribute to the collection property instructing it to use this editor.

Expand|Select|Wrap|Line Numbers
  1. <Editor(GetType(FieldCollection), GetType(UITypeEditor))> _
  2.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  3.     <Description("Fields Collection")> _
  4.     <Category("Behaviour")> _
  5.     Public Property Evarus_Fields() As Fields
  6.         Get
  7.             If TableFields Is Nothing Then
  8.                 TableFields = New Fields
  9.             End If
  10.             Return TableFields
  11.         End Get
  12.         Set(ByVal value As Fields)
  13.             TableFields = value
  14.         End Set
  15.     End Property
  16.  

1 3986
I have resolved my issue.
I needed to provide a “customized” collection editor for my typed class (Field).

Expand|Select|Wrap|Line Numbers
  1. Public Class FieldCollection
  2.         Inherits CollectionEditor
  3.         Public Sub New()
  4.             MyBase.New(GetType(List(Of Field)))
  5.         End Sub
  6.     End Class
  7.  
And then supplied an attribute to the collection property instructing it to use this editor.

Expand|Select|Wrap|Line Numbers
  1. <Editor(GetType(FieldCollection), GetType(UITypeEditor))> _
  2.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  3.     <Description("Fields Collection")> _
  4.     <Category("Behaviour")> _
  5.     Public Property Evarus_Fields() As Fields
  6.         Get
  7.             If TableFields Is Nothing Then
  8.                 TableFields = New Fields
  9.             End If
  10.             Return TableFields
  11.         End Get
  12.         Set(ByVal value As Fields)
  13.             TableFields = value
  14.         End Set
  15.     End Property
  16.  
Oct 19 '10 #2

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

Similar topics

3
by: Mark Broadbent | last post by:
In VB6 (using visual studio) it was possible to create a control array at design time by simply adding the control (e.g. textbox) and renaming it to what would become the first element e.g. ...
5
by: Rogerio Jun | last post by:
I create a custom control with a collection property. My question is : Can I override the method add of Collection ?
0
by: Paul Cook | last post by:
Hi I am trying to determine whether a control is being displayed at designtime or runtime but this piece of code doesn't seem to work correctly. Note that this is not a web user control (ascx)...
0
by: Mark | last post by:
I'd like to make a public property on a user control so that a person can drag and drop the user control onto their page, and then modify a public property of the user control at design time in the...
2
by: -=Chris=- | last post by:
Hello all, I've designed a custom bread crumb control for several of my asp.net projects. The default property of this control is a custom HyperLinkCollection I've created, which contains, you...
2
by: Charlie | last post by:
Hi: When I drag a my custom server control from the toolbox to design surface it appears invisible except for little green arrow. I can change the width and fill color of control in prop sheet...
2
by: Dennis | last post by:
I have a control which I wrote that has, of course, numerous properties. These properties nicely show up at design time in the property window for the user to set their value at design time. ...
1
by: rizwanahmed24 | last post by:
Hello I want to capture the event generated when a control (from toolbox) is added on to the panel at design time. I tried overriding OnControlAdded method, and capturing ControlAdded event but...
0
by: Ryan | last post by:
I have a custom control and would like to give it a property like the WebControl class's FONT property. I created the following importing from System.Drawing Public Property HeaderFont() As...
10
by: Allan Ebdrup | last post by:
I have a custom server web control that inserts another custom web server control in a templated child control (a wisard that inserts a header in its wizardstep) Now after switching to design view...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.