R
Ralf Müller
Hi folks!
I am developing a custom TreeView and I have got a problem with the
serialization of my TreeViewModel:
[Serializable]
public class NavigationTreeModel : ITreeModel {
public event EventHandler DataChanged;
private Folder _rootFolder;
private IList _rootElements;
public NavigationTreeModel() : this(null) {
}
public NavigationTreeModel(Folder root) {
_rootElements = new ArrayList();
RootFolder = root;
}
public Folder RootFolder {
get { return _rootFolder; }
set {
if (_rootFolder == value)
return;
if (_rootFolder != null)
_rootElements.Remove(_rootFolder);
_rootFolder = value;
if (_rootFolder != null) {
_rootElements.Add(_rootFolder);
}
OnDataChanged(EventArgs.Empty);
}
}
#region ITreeModel Member
public IList RootElements {
get {
if (_rootElements == null) {
_rootElements = new ArrayList();
if(RootFolder != null)
_rootElements.Add(RootFolder);
}
return _rootElements;
}
}
public IList GetChildren(object parent) {
if (parent is Folder) {
return ((Folder)parent).Folders;
}
return new ArrayList();
}
#endregion
protected virtual void OnDataChanged(EventArgs e) {
if (DataChanged != null)
DataChanged(this, e);
}
}
The model serializes perfectly until I set my TreeViewControl to handle its
DataChangedEvent. Then I get the following exception:
"Der Typ 'julitec.DM.Web.NavigationTreeModel' muss als 'Serializable'
markiert sein oder einen anderen TypeConverter als ReferenceConverter
haben." (= The type 'julitec.DM.Web.NavigationTreeModel' must be marked as
Serializable or have a TypeConverter other than ReferenceConverter)
I guess that is because my TreeViewControl is not serializable.
What I am asking myself (and you) now is the following: Should I really make
a Control serializable? I don't think it is a good pratice to do so since
none of the built in ASP.NET WebControls seems to be serializable. What else
could I do to overcome this problem?
Thanx in advance!
Greetings, Ralf
I am developing a custom TreeView and I have got a problem with the
serialization of my TreeViewModel:
[Serializable]
public class NavigationTreeModel : ITreeModel {
public event EventHandler DataChanged;
private Folder _rootFolder;
private IList _rootElements;
public NavigationTreeModel() : this(null) {
}
public NavigationTreeModel(Folder root) {
_rootElements = new ArrayList();
RootFolder = root;
}
public Folder RootFolder {
get { return _rootFolder; }
set {
if (_rootFolder == value)
return;
if (_rootFolder != null)
_rootElements.Remove(_rootFolder);
_rootFolder = value;
if (_rootFolder != null) {
_rootElements.Add(_rootFolder);
}
OnDataChanged(EventArgs.Empty);
}
}
#region ITreeModel Member
public IList RootElements {
get {
if (_rootElements == null) {
_rootElements = new ArrayList();
if(RootFolder != null)
_rootElements.Add(RootFolder);
}
return _rootElements;
}
}
public IList GetChildren(object parent) {
if (parent is Folder) {
return ((Folder)parent).Folders;
}
return new ArrayList();
}
#endregion
protected virtual void OnDataChanged(EventArgs e) {
if (DataChanged != null)
DataChanged(this, e);
}
}
The model serializes perfectly until I set my TreeViewControl to handle its
DataChangedEvent. Then I get the following exception:
"Der Typ 'julitec.DM.Web.NavigationTreeModel' muss als 'Serializable'
markiert sein oder einen anderen TypeConverter als ReferenceConverter
haben." (= The type 'julitec.DM.Web.NavigationTreeModel' must be marked as
Serializable or have a TypeConverter other than ReferenceConverter)
I guess that is because my TreeViewControl is not serializable.
What I am asking myself (and you) now is the following: Should I really make
a Control serializable? I don't think it is a good pratice to do so since
none of the built in ASP.NET WebControls seems to be serializable. What else
could I do to overcome this problem?
Thanx in advance!
Greetings, Ralf