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

Custom Type Collection

P: n/a
Hi,

I've created a component that allows me to store database information for
various types of databases my company uses. It uses a collection for each
type of database. Everything is working perfectly except when the component
is deleted from the page. Here are the details.

I add the component to the page from the toolbox and then add items using
the collection editor. I can delete those items from the collection using
the collection editor and the removed item's code is also deleted from the
codebehind page.

But if I add items to a collection using the collection editor and then
later delete the component from the page without first removing the
collection's items the individual items code is left in the cod-behind page.

Is there some way to get the component to clean up after itself if it's
deleted or a better way in general to create a component with a collection?

Here's the code:

Imports System

Imports System.ComponentModel

Public Class DatabaseLibrary

Inherits System.ComponentModel.Component

Private _AccessDatabaseCollection As AccessDatabaseCollection = New
AccessDatabaseCollection

Private _SQLDatabaseCollection As SQLDatabaseCollection = New
SQLDatabaseCollection

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Property AccessDatabases() As AccessDatabaseCollection

Get

Return _AccessDatabaseCollection

End Get

Set(ByVal Value As AccessDatabaseCollection)

_AccessDatabaseCollection = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Property SQLDatabases() As SQLDatabaseCollection

Get

Return _SQLDatabaseCollection

End Get

Set(ByVal Value As SQLDatabaseCollection)

_SQLDatabaseCollection = Value

End Set

End Property

#Region "Access"

Public Class AccessDatabaseCollection

Inherits CollectionBase

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Default Public Property Item(ByVal index As Integer) As AccessDatabase

Get

Return CType(MyBase.List.Item(index), AccessDatabase)

End Get

Set(ByVal Value As AccessDatabase)

List.Item(index) = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Function Add(ByVal database As AccessDatabase) As Integer

List.Add(database)

End Function

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Function IndexOf(ByVal database As AccessDatabase) As Int32

Return List.IndexOf(database)

End Function

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Sub Insert(ByVal index As Int32, ByVal database As AccessDatabase)

List.Insert(index, database)

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Sub Remove(ByVal database As AccessDatabase)

List.Remove(database)

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Function Contains(ByVal database As AccessDatabase) As Boolean

Return List.Contains(database)

End Function

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As
Object)

If Not value.GetType() Is GetType(AccessDatabase) Then

Throw New ArgumentException("Value must be of type
Fortunate.AccessDatabase.", "value")

End If

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value As
Object)

If Not value.GetType() Is GetType(AccessDatabase) Then

Throw New ArgumentException("Value must be of type
Fortunate.AccessDatabase.", "value")

End If

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As
Object, ByVal newValue As Object)

If Not newValue.GetType() Is GetType(AccessDatabase) Then

Throw New ArgumentException("newValue must be of type
Fortunate.AccessDatabase.", "newValue")

End If

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Protected Overrides Sub OnValidate(ByVal value As Object)

If Not value.GetType() Is GetType(AccessDatabase) Then

Throw New ArgumentException("value must be of type
Fortunate.AccessDatabase.", "value")

End If

End Sub

<DesignTimeVisible(False), ToolboxItem(False)> _

Public Class AccessDatabase

Inherits System.ComponentModel.Component

Private _UID As String

Private _PWD As String

Private _LocalPath As String

Private _DevelopmentPath As String

Private _StagingPath As String

Private _ProductionPath As String

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property UserID() As String

Get

Return _UID

End Get

Set(ByVal Value As String)

_UID = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property Password() As String

Get

Return _PWD

End Get

Set(ByVal Value As String)

_PWD = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property LocalPath() As String

Get

Return _LocalPath

End Get

Set(ByVal Value As String)

_LocalPath = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property DevelopmentPath() As String

Get

Return _DevelopmentPath

End Get

Set(ByVal Value As String)

_DevelopmentPath = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property StagingPath() As String

Get

Return _StagingPath

End Get

Set(ByVal Value As String)

_StagingPath = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property ProductionPath() As String

Get

Return _ProductionPath

End Get

Set(ByVal Value As String)

_ProductionPath = Value

End Set

End Property

End Class

End Class

#End Region

#Region "SQL"

Public Class SQLDatabaseCollection

Inherits CollectionBase

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Default Public Property Item(ByVal index As Integer) As SQLDatabase

Get

Return CType(MyBase.List.Item(index), SQLDatabase)

End Get

Set(ByVal Value As SQLDatabase)

List.Item(index) = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Function Add(ByVal database As SQLDatabase) As Integer

List.Add(database)

End Function

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Function IndexOf(ByVal database As SQLDatabase) As Int32

Return List.IndexOf(database)

End Function

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Sub Insert(ByVal index As Int32, ByVal database As SQLDatabase)

List.Insert(index, database)

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Sub Remove(ByVal database As SQLDatabase)

List.Remove(database)

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Public Function Contains(ByVal database As SQLDatabase) As Boolean

Return List.Contains(database)

End Function

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As
Object)

If Not value.GetType() Is GetType(SQLDatabase) Then

Throw New ArgumentException("Value must be of type Fortunate.SQLDatabase.",
"value")

End If

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value As
Object)

If Not value.GetType() Is GetType(SQLDatabase) Then

Throw New ArgumentException("Value must be of type Fortunate.SQLDatabase.",
"value")

End If

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As
Object, ByVal newValue As Object)

If Not newValue.GetType() Is GetType(SQLDatabase) Then

Throw New ArgumentException("newValue must be of type
Fortunate.SQLDatabase.", "newValue")

End If

End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _

Protected Overrides Sub OnValidate(ByVal value As Object)

If Not value.GetType() Is GetType(SQLDatabase) Then

Throw New ArgumentException("value must be of type Fortunate.SQLDatabase.",
"value")

End If

End Sub

<DesignTimeVisible(False), ToolboxItem(False)> _

Public Class SQLDatabase

Inherits System.ComponentModel.Component

Private _UID As String

Private _PWD As String

Private _LocalServer As String = "localhost"

Private _DevelopmentServer As String

Private _StagingServer As String

Private _ProductionServer As String

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property UserID() As String

Get

Return _UID

End Get

Set(ByVal Value As String)

_UID = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property Password() As String

Get

Return _PWD

End Get

Set(ByVal Value As String)

_PWD = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property LocalServer() As String

Get

Return _LocalServer

End Get

Set(ByVal Value As String)

_LocalServer = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property DevelopmentServer() As String

Get

Return _DevelopmentServer

End Get

Set(ByVal Value As String)

_DevelopmentServer = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property StagingServer() As String

Get

Return _StagingServer

End Get

Set(ByVal Value As String)

_StagingServer = Value

End Set

End Property

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _

Public Property ProductionServer() As String

Get

Return _ProductionServer

End Get

Set(ByVal Value As String)

_ProductionServer = Value

End Set

End Property

End Class

End Class

#End Region

End Class
Thanks in advance for any help with this.
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"S. Justin Gengo" <sj*****@aboutfortunate.com> schrieb

Here's the code:


Could you please copy the code to notepad first, then into your posting? It
keeps identation and does not insert empty lines. It's better for us to read
and to help you.
--
Armin

Nov 20 '05 #2

P: n/a
Armin,

Sure. Thanks for taking a look!

Imports System
Imports System.ComponentModel

Public Class DatabaseLibrary
Inherits System.ComponentModel.Component

Private _AccessDatabaseCollection As AccessDatabaseCollection = New
AccessDatabaseCollection
Private _SQLDatabaseCollection As SQLDatabaseCollection = New
SQLDatabaseCollection
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Property AccessDatabases() As AccessDatabaseCollection
Get
Return _AccessDatabaseCollection
End Get
Set(ByVal Value As AccessDatabaseCollection)
_AccessDatabaseCollection = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Property SQLDatabases() As SQLDatabaseCollection
Get
Return _SQLDatabaseCollection
End Get
Set(ByVal Value As SQLDatabaseCollection)
_SQLDatabaseCollection = Value
End Set
End Property

#Region "Access"

Public Class AccessDatabaseCollection
Inherits CollectionBase
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Default Public Property Item(ByVal index As Integer) As
AccessDatabase
Get
Return CType(MyBase.List.Item(index), AccessDatabase)
End Get
Set(ByVal Value As AccessDatabase)
List.Item(index) = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Function Add(ByVal database As AccessDatabase) As Integer
List.Add(database)
End Function
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Function IndexOf(ByVal database As AccessDatabase) As Int32
Return List.IndexOf(database)
End Function
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Sub Insert(ByVal index As Int32, ByVal database As
AccessDatabase)
List.Insert(index, database)
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Sub Remove(ByVal database As AccessDatabase)
List.Remove(database)
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Function Contains(ByVal database As AccessDatabase) As
Boolean
Return List.Contains(database)
End Function
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value
As Object)
If Not value.GetType() Is GetType(AccessDatabase) Then
Throw New ArgumentException("Value must be of type
Fortunate.AccessDatabase.", "value")
End If
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value
As Object)
If Not value.GetType() Is GetType(AccessDatabase) Then
Throw New ArgumentException("Value must be of type
Fortunate.AccessDatabase.", "value")
End If
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue
As Object, ByVal newValue As Object)
If Not newValue.GetType() Is GetType(AccessDatabase) Then
Throw New ArgumentException("newValue must be of type
Fortunate.AccessDatabase.", "newValue")
End If
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Protected Overrides Sub OnValidate(ByVal value As Object)
If Not value.GetType() Is GetType(AccessDatabase) Then
Throw New ArgumentException("value must be of type
Fortunate.AccessDatabase.", "value")
End If
End Sub

<DesignTimeVisible(False), ToolboxItem(False)> _
Public Class AccessDatabase
Inherits System.ComponentModel.Component

Private _UID As String
Private _PWD As String
Private _LocalPath As String
Private _DevelopmentPath As String
Private _StagingPath As String
Private _ProductionPath As String
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property UserID() As String
Get
Return _UID
End Get
Set(ByVal Value As String)
_UID = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property Password() As String
Get
Return _PWD
End Get
Set(ByVal Value As String)
_PWD = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property LocalPath() As String
Get
Return _LocalPath
End Get
Set(ByVal Value As String)
_LocalPath = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property DevelopmentPath() As String
Get
Return _DevelopmentPath
End Get
Set(ByVal Value As String)
_DevelopmentPath = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property StagingPath() As String
Get
Return _StagingPath
End Get
Set(ByVal Value As String)
_StagingPath = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property ProductionPath() As String
Get
Return _ProductionPath
End Get
Set(ByVal Value As String)
_ProductionPath = Value
End Set
End Property
End Class
End Class

#End Region

#Region "SQL"

Public Class SQLDatabaseCollection
Inherits CollectionBase
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Default Public Property Item(ByVal index As Integer) As SQLDatabase
Get
Return CType(MyBase.List.Item(index), SQLDatabase)
End Get
Set(ByVal Value As SQLDatabase)
List.Item(index) = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Function Add(ByVal database As SQLDatabase) As Integer
List.Add(database)
End Function
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Function IndexOf(ByVal database As SQLDatabase) As Int32
Return List.IndexOf(database)
End Function
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Sub Insert(ByVal index As Int32, ByVal database As
SQLDatabase)
List.Insert(index, database)
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Sub Remove(ByVal database As SQLDatabase)
List.Remove(database)
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Function Contains(ByVal database As SQLDatabase) As Boolean
Return List.Contains(database)
End Function
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value
As Object)
If Not value.GetType() Is GetType(SQLDatabase) Then
Throw New ArgumentException("Value must be of type
Fortunate.SQLDatabase.", "value")
End If
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value
As Object)
If Not value.GetType() Is GetType(SQLDatabase) Then
Throw New ArgumentException("Value must be of type
Fortunate.SQLDatabase.", "value")
End If
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue
As Object, ByVal newValue As Object)
If Not newValue.GetType() Is GetType(SQLDatabase) Then
Throw New ArgumentException("newValue must be of type
Fortunate.SQLDatabase.", "newValue")
End If
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Protected Overrides Sub OnValidate(ByVal value As Object)
If Not value.GetType() Is GetType(SQLDatabase) Then
Throw New ArgumentException("value must be of type
Fortunate.SQLDatabase.", "value")
End If
End Sub

<DesignTimeVisible(False), ToolboxItem(False)> _
Public Class SQLDatabase
Inherits System.ComponentModel.Component

Private _UID As String
Private _PWD As String
Private _LocalServer As String = "localhost"
Private _DevelopmentServer As String
Private _StagingServer As String
Private _ProductionServer As String
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property UserID() As String
Get
Return _UID
End Get
Set(ByVal Value As String)
_UID = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property Password() As String
Get
Return _PWD
End Get
Set(ByVal Value As String)
_PWD = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property LocalServer() As String
Get
Return _LocalServer
End Get
Set(ByVal Value As String)
_LocalServer = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property DevelopmentServer() As String
Get
Return _DevelopmentServer
End Get
Set(ByVal Value As String)
_DevelopmentServer = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property StagingServer() As String
Get
Return _StagingServer
End Get
Set(ByVal Value As String)
_StagingServer = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> _
Public Property ProductionServer() As String
Get
Return _ProductionServer
End Get
Set(ByVal Value As String)
_ProductionServer = Value
End Set
End Property
End Class
End Class

#End Region

End Class

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"S. Justin Gengo" <sj*****@aboutfortunate.com> schrieb

Here's the code:
Could you please copy the code to notepad first, then into your posting?

It keeps identation and does not insert empty lines. It's better for us to read and to help you.
--
Armin

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.