Error when trying to Inherit a control and then make it Serializab

G

Guest

Hi. I am trying to do something that seems very simple. I want to create a
class that inherits from the ListViewItem Control so that I can add a few
custom properties to it. I then want to make it serializable so that I can
save the ListViewItems contained in the ListView. My code snippet is this:

[Serializable()]
public class test : System.Windows.Forms.ListViewItem
{
public test(string s, int i): base(s, i) {}
protected test(SerializationInfo si, StreamingContext context)
: base(si,context){}
//additional properties here.
}

When attempting to compile I get the error message:
....\MainForm.cs(1077):
'System.Windows.Forms.ListViewItem.ListViewItem(System.Runtime.Serialization.SerializationInfo,
System.Runtime.Serialization.StreamingContext)' is inaccessible due to its
protection level

I added the second constructor
"protected test(SerializationInfo si, StreamingContext context)
: base(si,context){}"
in an attempt to fix a problem that was occuring during runtime. I was
getting an exception error that the class could not be deserialized.

Thanks for the help in advance.
 
C

Christian Gudrian

Kelly said:
I then want to make it serializable so that I can
save the ListViewItems contained in the ListView.

AFAIK, serialization requires each ancestor class to be serializable as
well.

Christian
 
G

Guest

Christian,

I believe the ListViewItems class IS serializable. I have successfully
serialized and deserialized this class. I just run into prolbems when I try
to inherit it.

-Kelly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top