|
-
Oct 20th, 2003, 01:52 PM
#1
Thread Starter
Hyperactive Member
Inherited Class and .Clone method..[RESOLVED]
I created my own class:
Code:
Public Class M3ListViewItem
Inherits System.Windows.Forms.ListViewItem
Private mintType As Integer
Public Property Type() as Integer...
End Class
In order to add a Type variable to the ListViewItem class that already existed.
The problem is when I call the Clone method, I get a regular ListViewItem back and the Type property is reset to Zero. How can I get around this?
I tried overloading the Clone method, but I can't return a different type on an overloaded method...
Thanks,
Ben
Last edited by BenFinkel; Oct 20th, 2003 at 02:29 PM.
-
Oct 20th, 2003, 01:56 PM
#2
You have to Shadow it to return a different value. BUT that means if it is cast down to a regular ListViewItem then the original Clone method will be called instead of yours. That probably wont be an issue but just so you know.
-
Oct 20th, 2003, 01:57 PM
#3
Thread Starter
Hyperactive Member
Shadow..interesting...
Like So?:
Public Shadows Function Clone() As M3ListViewItem
And out of curiosity, what would my clone method look like?
How is this:
Code:
Public Shadows Function Clone() As M3ListViewItem
dim lviNew as New M3ListViewItem()
lviNew = me.Clone
lviNew.Type = me.Type
Clone = lviNew
End Function
-
Oct 20th, 2003, 02:20 PM
#4
However you want to do it. You can either go thru each property or if I were you I'd use serialization. If you serialize it for cloning then if you add or change properties later then you wont have to change the clone method.
-
Oct 20th, 2003, 02:25 PM
#5
Thread Starter
Hyperactive Member
Heh, feel like giving me a quick lesson in serialization?
-
Oct 20th, 2003, 02:31 PM
#6
Search for 'BinaryFormatter' I remember seeing some examples posted previously on this board. Its very easy though. If you are still stuck after those then I'll post an example.
Last edited by Edneeis; Oct 20th, 2003 at 02:37 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|