G
Guest
Hello,
I am working on creating a MyUserControl which has a custom property Employees which is of type EmployeeCollection. The EmployeeCollection is a collection which holds employee objects. I need to provide a collectioneditor for employees (like tab pages) with which the users will be able to add/remove employees from the user control on design time. I am having certain problems like:
1> In the collectioneditor the type is 'object' instead of employee
2> On adding certain employees in the collection editor I get type mismatch error message as the objects being added to the emplyee collection are of type object and not employee.
Below is the sourcecode of my usercontrol. To test it you would need to include this in a project and build it, and use it on a form. The issue would be duplicated in a sec.
'===sourcecode begins==
Imports Syste
Imports System.ComponentMode
Imports System.ComponentModel.Desig
Public Class MyUserContro
Inherits System.Windows.Forms.UserContro
Private m_colEmployees As EmployeeCollectio
#Region " Windows Form Designer generated code
Public Sub New(
MyBase.New(
'This call is required by the Windows Form Designer
InitializeComponent(
'Add any initialization after the InitializeComponent() cal
Me.BackColor = Color.Pin
m_colEmployees = New EmployeeCollectio
End Su
'UserControl overrides dispose to clean up the component list
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean
If disposing The
If Not (components Is Nothing) The
components.Dispose(
End I
End I
MyBase.Dispose(disposing
End Su
'Required by the Windows Form Designe
Private components As System.ComponentModel.IContaine
'NOTE: The following procedure is required by the Windows Form Designe
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent(
Me.Name = "MyEmployeeLabel
Me.Size = New System.Drawing.Size(384, 192
End Su
#End Regio
'_______________________________________________________________________________
'Employee
'_______________________________________________________________________________
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor("EmployeeCollectionEditor", "UITypeEditor"), Category("MyUserControl")>
Public Property Employee() As EmployeeCollectio
Ge
Return m_colEmployee
End Ge
Set(ByVal Value As EmployeeCollection
m_colEmployees = Valu
End Se
End Propert
End Clas
Public Class EmployeeCollectio
Inherits CollectionBas
'```````````````````````````````````````````````````````````````````````````````
'Method
'```````````````````````````````````````````````````````````````````````````````
'_______________________________________________________________________________
'Ad
'_______________________________________________________________________________
Public Sub Add(ByVal v_objEmployee As Employee
MyBase.List.Add(v_objEmployee
End Su
'_______________________________________________________________________________
'ite
'_______________________________________________________________________________
Public Function Item(ByVal index As Integer) As Employe
Return (CType(MyBase.List.Item(index), Employee)
End Functio
End Clas
Public Class Employe
Private m_strName As Strin
Private m_intAge As Intege
Public Sub New(
End Su
Public Sub New(ByVal v_strName As String, ByVal v_intAge As Integer
m_strName = v_strNam
m_intAge = v_intAg
End Su
Public Property Name() As Strin
Ge
Return m_strNam
End Ge
Set(ByVal Value As String
m_strName = Valu
End Set
End Property
Public Property Age() As Integer
Get
Return m_intAge
End Get
Set(ByVal Value As Integer)
m_intAge = Value
End Set
End Property
End Class
Public Class EmployeeCollectionEditor
Inherits CollectionEditor
Public Sub New()
MyBase.New(GetType(Employee))
End Sub
Protected Overrides Function CreateCollectionItemType() As System.Type
Return GetType(Employee)
End Function
Protected Overrides Function CreateNewItemTypes() As System.Type()
Dim objType() As Type = {GetType(Employee)}
Return objType
End Function
End Class
'===sourcecode ends===
Waiting for your expert advice urgently. Please help.
Thanks
dev
I am working on creating a MyUserControl which has a custom property Employees which is of type EmployeeCollection. The EmployeeCollection is a collection which holds employee objects. I need to provide a collectioneditor for employees (like tab pages) with which the users will be able to add/remove employees from the user control on design time. I am having certain problems like:
1> In the collectioneditor the type is 'object' instead of employee
2> On adding certain employees in the collection editor I get type mismatch error message as the objects being added to the emplyee collection are of type object and not employee.
Below is the sourcecode of my usercontrol. To test it you would need to include this in a project and build it, and use it on a form. The issue would be duplicated in a sec.
'===sourcecode begins==
Imports Syste
Imports System.ComponentMode
Imports System.ComponentModel.Desig
Public Class MyUserContro
Inherits System.Windows.Forms.UserContro
Private m_colEmployees As EmployeeCollectio
#Region " Windows Form Designer generated code
Public Sub New(
MyBase.New(
'This call is required by the Windows Form Designer
InitializeComponent(
'Add any initialization after the InitializeComponent() cal
Me.BackColor = Color.Pin
m_colEmployees = New EmployeeCollectio
End Su
'UserControl overrides dispose to clean up the component list
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean
If disposing The
If Not (components Is Nothing) The
components.Dispose(
End I
End I
MyBase.Dispose(disposing
End Su
'Required by the Windows Form Designe
Private components As System.ComponentModel.IContaine
'NOTE: The following procedure is required by the Windows Form Designe
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent(
Me.Name = "MyEmployeeLabel
Me.Size = New System.Drawing.Size(384, 192
End Su
#End Regio
'_______________________________________________________________________________
'Employee
'_______________________________________________________________________________
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor("EmployeeCollectionEditor", "UITypeEditor"), Category("MyUserControl")>
Public Property Employee() As EmployeeCollectio
Ge
Return m_colEmployee
End Ge
Set(ByVal Value As EmployeeCollection
m_colEmployees = Valu
End Se
End Propert
End Clas
Public Class EmployeeCollectio
Inherits CollectionBas
'```````````````````````````````````````````````````````````````````````````````
'Method
'```````````````````````````````````````````````````````````````````````````````
'_______________________________________________________________________________
'Ad
'_______________________________________________________________________________
Public Sub Add(ByVal v_objEmployee As Employee
MyBase.List.Add(v_objEmployee
End Su
'_______________________________________________________________________________
'ite
'_______________________________________________________________________________
Public Function Item(ByVal index As Integer) As Employe
Return (CType(MyBase.List.Item(index), Employee)
End Functio
End Clas
Public Class Employe
Private m_strName As Strin
Private m_intAge As Intege
Public Sub New(
End Su
Public Sub New(ByVal v_strName As String, ByVal v_intAge As Integer
m_strName = v_strNam
m_intAge = v_intAg
End Su
Public Property Name() As Strin
Ge
Return m_strNam
End Ge
Set(ByVal Value As String
m_strName = Valu
End Set
End Property
Public Property Age() As Integer
Get
Return m_intAge
End Get
Set(ByVal Value As Integer)
m_intAge = Value
End Set
End Property
End Class
Public Class EmployeeCollectionEditor
Inherits CollectionEditor
Public Sub New()
MyBase.New(GetType(Employee))
End Sub
Protected Overrides Function CreateCollectionItemType() As System.Type
Return GetType(Employee)
End Function
Protected Overrides Function CreateNewItemTypes() As System.Type()
Dim objType() As Type = {GetType(Employee)}
Return objType
End Function
End Class
'===sourcecode ends===
Waiting for your expert advice urgently. Please help.
Thanks
dev