Results 1 to 6 of 6

Thread: Inherited Class and .Clone method..[RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297

    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.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    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

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    Heh, feel like giving me a quick lesson in serialization?

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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
  •  



Click Here to Expand Forum to Full Width