[RESOLVED] [2005] persistence properties
Hi guys...
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...
Re: [2005] persistence properties
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.
Re: [2005] persistence properties
thx for the tip... i will google it and let you know what i find...
Re: [2005] persistence properties
by the way... which way the items and subitems of a listview are saved in design time ?
Re: [2005] persistence properties
i've added SerializeObject and DeserializeObject procedures... im able to serialize this objects at runtime...
but what about design time...as in the items of a listview... ???
Re: [2005] persistence properties
In .NET 2.0 you should inherit System.Collections.ObjectModel.Collection(Of T) rather than CollectionBase.
Re: [2005] persistence properties
Quote:
Originally Posted by jmcilhinney
In .NET 2.0 you should inherit System.Collections.ObjectModel.Collection(Of T) rather than CollectionBase.
Thx for the tip jm
but how to persist data at design time ?
VB Code:
<Serializable()> _
Public Class Versions
Inherits System.Collections.ObjectModel.Collection(Of Version)
''' <summary>
''' Inserts the item.
''' </summary>
''' <param name="index">The index.</param>
''' <param name="newItem">The new item.</param>
Protected Overloads Sub InsertItem( _
ByVal index As Integer, ByVal newItem As Version)
MyBase.InsertItem(index, newItem)
End Sub
''' <summary>
''' Sets the item.
''' </summary>
''' <param name="index">The index.</param>
''' <param name="newItem">The new item.</param>
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>.
''' </summary>
Protected Overrides Sub ClearItems()
MyBase.ClearItems()
End Sub
End Class
1 Attachment(s)
Re: [2005] persistence properties
let me show you what i want
Re: [2005] persistence properties
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.
Re: [2005] persistence properties
Quote:
Originally Posted by Shaggy Hiker
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.
or i am doing something wrong...
1 Attachment(s)
Re: [2005] persistence properties
ok... i solved myself... so simple... i forgot to Initialize the collection property...
VB Code:
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.Text = "Form1"
Me.VersionManager = New Versions
End Sub
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...
thx for all your help guys...
2 Attachment(s)
Re: [RESOLVED] [2005] persistence properties
Finally i made my windows forms version manager... works in design and run time...
no need to insert version history in the code comments... just use this component in your base form...
thx a lot for all the help...