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

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
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
 
Back
Top