im trying to implement a version manager in my base form. For that i made an object that inherits a collection... its working fine except the data entered is not saved... how to persist properties data ?
this is my code
VB Code:
Imports System.Collections
Public Class Base
''' <summary>
''' Gets or sets the version manager.
''' </summary>
''' <value>The version manager.</value>
Public Property VersionManager() As Versions
Get
VersionManager = mVersionManager
End Get
Set(ByVal value As Versions)
mVersionManager = value
End Set
End Property
Dim mVersionManager As Versions
End Class
VB Code:
Public Class Version
''' <summary>
''' Gets or sets the form major version.
''' </summary>
''' <value>The form major version.</value>
Public Property FormMajorVersion() As Integer
Get
FormMajorVersion = mFormMajorVersion
End Get
Set(ByVal value As Integer)
mFormMajorVersion = value
End Set
End Property
Dim mFormMajorVersion As Integer
''' <summary>
''' Gets or sets the form minor version.
''' </summary>
''' <value>The form minor version.</value>
Public Property FormMinorVersion() As Integer
Get
FormMinorVersion = mFormMinorVersion
End Get
Set(ByVal value As Integer)
mFormMinorVersion = value
End Set
End Property
Dim mFormMinorVersion As Integer
''' <summary>
''' Gets or sets the username.
''' </summary>
''' <value>The username.</value>
Public Property Username() As String
Get
Username = mUsername
End Get
Set(ByVal value As String)
mUsername = value
End Set
End Property
Dim mUsername As String
''' <summary>
''' Gets or sets the comments.
''' </summary>
''' <value>The comments.</value>
Public Property Comments() As String
Get
Comments = mComments
End Get
Set(ByVal value As String)
mComments = value
End Set
End Property
Dim mComments As String
''' <summary>
''' Initializes a new instance of the <see cref="Version" /> class.
''' </summary>
Public Sub New()
End Sub
''' <summary>
''' Initializes a new instance of the <see cref="Version" /> class.
''' </summary>
''' <param name="majorVersion">The major version.</param>
''' <param name="minorVersion">The minor version.</param>
''' <param name="userName">Name of the user.</param>
''' <param name="comments">The comments.</param>
Public Sub New(ByVal majorVersion As Integer, ByVal minorVersion As Integer, ByVal userName As String, Optional ByVal comments As String = Nothing)
mFormMajorVersion = majorVersion
mFormMinorVersion = minorVersion
mUsername = userName
mComments = comments
End Sub
''' <summary>
''' Initializes a new instance of the <see cref="Version" /> class.
''' </summary>
''' <param name="e">The e.</param>
Public Sub New(ByVal e As Version)
mFormMajorVersion = e.FormMajorVersion
mFormMinorVersion = e.FormMinorVersion
mUsername = e.Username
mComments = e.Comments
End Sub
End Class
VB Code:
Public Class Versions
Inherits CollectionBase
''' <summary>
''' Adds the specified e.
''' </summary>
''' <param name="e">The e.</param>
Public Sub add(ByVal e As Version)
List.Add(e)
End Sub
''' <summary>
''' Deletes the specified e.
''' </summary>
''' <param name="e">The e.</param>
Public Sub delete(ByVal e As Version)
List.Remove(e)
End Sub
''' <summary>
''' Deletes the specified index.
''' </summary>
''' <param name="index">The index.</param>
Public Sub delete(ByVal index As Integer)
If index < 0 Or index > List.Count - 1 Then
Throw New Exception("Invalid index to remove")
End If
List.RemoveAt(index)
End Sub
''' <summary>
''' Gets the Item.
''' </summary>
''' <value>The search.</value>
Default Public Overridable ReadOnly Property Item(ByVal index As Integer) As Version
Get
Return CType(Me.List(index), Version)
End Get
End Property
''' <summary>
''' Gets the search.
''' </summary>
''' <value>The search.</value>
Public ReadOnly Property Search(ByVal mjorVersion As Integer) As Version
Get
For Each e As Version In Me.List
If e.FormMajorVersion = mjorVersion Then Return e
Next
Return Nothing
End Get
End Property
End Class
thx in advance...
Last edited by zuperman; Jan 22nd, 2007 at 07:17 PM.
Reason: separate classes
I'd look into the Serializable() attribute, to see if that is to your liking. It's mighty fast to implement, but a casual glance at your code suggests that it might be overkill, as you seem to be trying to persist only a handful of values. Serializable gives you a fast way to store/retrieve class maps (classes within classes within classes etc.), but for just a few items, other options exist, especially in 2005 with that MySettings, or whatever it is called.
Protected Overloads Sub SetItem(ByVal index As Integer, _
ByVal newItem As Version)
Dim replaced As Version = Items(index)
MyBase.SetItem(index, newItem)
End Sub
''' <summary>
''' Removes the element at the specified index of the <see cref="T:System.Collections.ObjectModel.Collection`1"></see>.
''' </summary>
''' <param name="index">The zero-based index of the element to remove.</param>
''' <exception cref="T:System.ArgumentOutOfRangeException">index is less than zero.-or-index is equal to or greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"></see>.</exception>
Protected Overrides Sub RemoveItem(ByVal index As Integer)
Dim removedItem As Version = Items(index)
MyBase.RemoveItem(index)
End Sub
''' <summary>
''' Removes all elements from the <see cref="T:System.Collections.ObjectModel.Collection`1"></see>.
Wow, it doesn't persist automatically? I thought anything you did in design view was saved when you saved the project. I wasn't aware of anything that got reset.
Wow, it doesn't persist automatically? I thought anything you did in design view was saved when you saved the project. I wasn't aware of anything that got reset.
Here it is the sample project...in case you face the same problem...
one thing has to be implemented... serialize the Versions collection in the base finalize destructor and deserialize in the base constructor... or else you loose data when you close the form...