473,669 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serious Serialization problem

I've made an inherited ListView control with a customized ColumnHeader Type.
I've overwritten the Columns property with a collection of my custom
ColumnHeader items. Now I would like to implement serialization so that
columns are persisted from designtime to runtime. But I cannot get it to
work.

I think it's because I don't know how to implement the type converter
correctly. Here's my suggestion for the type converter. Sample code for the
ListView, ColumnHeaderCol lection and ColumnHeaderIte m is supplied below. Can
anybody tell me what's wrong?

Cheers, Johnny J.

public class MyListViewColum nConverter : TypeConverter
{
public override bool CanConvertTo
(ITypeDescripto rContext context, Type destinationType )
{
if (destinationTyp e == typeof(Instance Descriptor))
{
return true;
}
return base.CanConvert To(context, destinationType );
}
public override object ConvertTo(IType DescriptorConte xt context, CultureInfo
culture, object value, Type destinationType )
{
if (destinationTyp e == typeof(Instance Descriptor) && value is
MyListViewColum n)
{
MyListViewColum nitem = (MyListViewColu mn)value;
ConstructorInfo ci = typeof(MyListVi ewColumn).GetCo nstructor(new Type[]
{ });
if (ci != null)
{
return new InstanceDescrip tor(ci, null, false);
}
}
return base.ConvertTo( context, culture, value, destinationType );
}
}

*************** *************** *************** *************
Listview, ColumnheaderCol lection, ColumnHeaderIte m code:
namespace MyListView
{
public class MyListView : ListView
{
private MyColumnHeaderC ollection myListViewColum nHeaders = null;
public MyListView()
{
myListViewColum nHeaders = new MyColumnHeaderC ollection(this) ;
//Other Code
}
public MyListView(ICon tainer container)
{
myListViewColum nHeaders = new MyColumnHeaderC ollection(this) ;
container.Add(t his);
//Other Code
}
[Localizable(tru e)]
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
[Editor("System. Windows.Forms.D esign.ColumnHea derCollectionEd itor,
System.Design, Version=2.0.0.0 , Culture=neutral ,
PublicKeyToken= b03f5f7f11d50a3 a", typeof(UITypeEd itor))]
[MergablePropert y(false)]
public new MyColumnHeaderC ollection Columns
{
get { return myListViewColum nHeaders; }
}
//Other Code
}
[DesignTimeVisib le(false)]
public class MyColumnHeaderC ollection : ListView.Column HeaderCollectio n
{
private SortedList columnList = new SortedList();
public new MyListViewColum n this[int index]
{
get
{ return (MyListViewColu mn)columnList.G etByIndex(index ); }
}
public override ColumnHeader Add(string str, int width, HorizontalAlign ment
textAlign)
{
MyListViewColum n column = new MyListViewColum n(str, width, textAlign);
this.Add(column );
return column;
}
public override int Add(ColumnHeade r column)
{
return this.Add(new MyListViewColum n(column));
}
public override void AddRange(Column Header[] values)
{
for (int index = 0; index < values.Length; index++)
{
this.Add(new MyListViewColum n(values[index]));
}
}
public int Add(MyListViewC olumn column)
{
int retValue = base.Add(column );
columnList.Add( column.ColumnID , column);
return retValue;
}
public new void Remove(ColumnHe ader column)
{
base.Remove(col umn);
columnList.Remo ve(((MyListView Column)column). ColumnID);
}
public new void RemoveAt(int index)
{
ColumnHeader column = this[index];
this.Remove(col umn);
}
public new void Clear()
{
base.Clear();
columnList.Clea r();
}
}
[DesignTimeVisib le(false)]
[TypeConverter(t ypeof(MyListVie wColumnConverte r))]
public class MyListViewColum n : ColumnHeader
{
private int m_ColumnID = 0;
private static int autoColumnID = 0;
public MyListViewColum n()
{
Initialize("", 60, HorizontalAlign ment.Left);
}
public MyListViewColum n(string str, int width, HorizontalAlign ment
textAlign)
{
Initialize(str, width, textAlign);
}
public MyListViewColum n(ColumnHeader column)
{
Initialize(colu mn.Text, column.Width, column.TextAlig n);
}
private void Initialize(stri ng str, int width, HorizontalAlign ment
textAlign)
{
base.Text = str;
base.Width = width;
base.TextAlign = textAlign;
m_ColumnID = autoColumnID++;
}
[Browsable(false )]
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Visible)]
public int ColumnID
{
get { return m_ColumnID; }
}
}
}
Sep 13 '07 #1
1 1704
I discovered I had missed a [Serializable] attribute on the MyListViewColum n
class. But that doesn't help - I get the error message:
MyListViewColum nConverter is unable to convert 'MyListView.MyL istViewColumn'
to 'System.Compone ntModel.Design. Serialization.I nstanceDescript or'.

/Johnny J.

"Johnny J." <jo**@altcom.se wrote in message
news:uS******** ******@TK2MSFTN GP03.phx.gbl...
I've made an inherited ListView control with a customized ColumnHeader
Type. I've overwritten the Columns property with a collection of my custom
ColumnHeader items. Now I would like to implement serialization so that
columns are persisted from designtime to runtime. But I cannot get it to
work.

I think it's because I don't know how to implement the type converter
correctly. Here's my suggestion for the type converter. Sample code for
the ListView, ColumnHeaderCol lection and ColumnHeaderIte m is supplied
below. Can anybody tell me what's wrong?

Cheers, Johnny J.

public class MyListViewColum nConverter : TypeConverter
{
public override bool CanConvertTo
(ITypeDescripto rContext context, Type destinationType )
{
if (destinationTyp e == typeof(Instance Descriptor))
{
return true;
}
return base.CanConvert To(context, destinationType );
}
public override object ConvertTo(IType DescriptorConte xt context,
CultureInfo culture, object value, Type destinationType )
{
if (destinationTyp e == typeof(Instance Descriptor) && value is
MyListViewColum n)
{
MyListViewColum nitem = (MyListViewColu mn)value;
ConstructorInfo ci = typeof(MyListVi ewColumn).GetCo nstructor(new Type[]
{ });
if (ci != null)
{
return new InstanceDescrip tor(ci, null, false);
}
}
return base.ConvertTo( context, culture, value, destinationType );
}
}

*************** *************** *************** *************
Listview, ColumnheaderCol lection, ColumnHeaderIte m code:
namespace MyListView
{
public class MyListView : ListView
{
private MyColumnHeaderC ollection myListViewColum nHeaders = null;
public MyListView()
{
myListViewColum nHeaders = new MyColumnHeaderC ollection(this) ;
//Other Code
}
public MyListView(ICon tainer container)
{
myListViewColum nHeaders = new MyColumnHeaderC ollection(this) ;
container.Add(t his);
//Other Code
}
[Localizable(tru e)]
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
[Editor("System. Windows.Forms.D esign.ColumnHea derCollectionEd itor,
System.Design, Version=2.0.0.0 , Culture=neutral ,
PublicKeyToken= b03f5f7f11d50a3 a", typeof(UITypeEd itor))]
[MergablePropert y(false)]
public new MyColumnHeaderC ollection Columns
{
get { return myListViewColum nHeaders; }
}
//Other Code
}
[DesignTimeVisib le(false)]
public class MyColumnHeaderC ollection : ListView.Column HeaderCollectio n
{
private SortedList columnList = new SortedList();
public new MyListViewColum n this[int index]
{
get
{ return (MyListViewColu mn)columnList.G etByIndex(index ); }
}
public override ColumnHeader Add(string str, int width,
HorizontalAlign ment textAlign)
{
MyListViewColum n column = new MyListViewColum n(str, width, textAlign);
this.Add(column );
return column;
}
public override int Add(ColumnHeade r column)
{
return this.Add(new MyListViewColum n(column));
}
public override void AddRange(Column Header[] values)
{
for (int index = 0; index < values.Length; index++)
{
this.Add(new MyListViewColum n(values[index]));
}
}
public int Add(MyListViewC olumn column)
{
int retValue = base.Add(column );
columnList.Add( column.ColumnID , column);
return retValue;
}
public new void Remove(ColumnHe ader column)
{
base.Remove(col umn);
columnList.Remo ve(((MyListView Column)column). ColumnID);
}
public new void RemoveAt(int index)
{
ColumnHeader column = this[index];
this.Remove(col umn);
}
public new void Clear()
{
base.Clear();
columnList.Clea r();
}
}
[DesignTimeVisib le(false)]
[TypeConverter(t ypeof(MyListVie wColumnConverte r))]
public class MyListViewColum n : ColumnHeader
{
private int m_ColumnID = 0;
private static int autoColumnID = 0;
public MyListViewColum n()
{
Initialize("", 60, HorizontalAlign ment.Left);
}
public MyListViewColum n(string str, int width, HorizontalAlign ment
textAlign)
{
Initialize(str, width, textAlign);
}
public MyListViewColum n(ColumnHeader column)
{
Initialize(colu mn.Text, column.Width, column.TextAlig n);
}
private void Initialize(stri ng str, int width, HorizontalAlign ment
textAlign)
{
base.Text = str;
base.Width = width;
base.TextAlign = textAlign;
m_ColumnID = autoColumnID++;
}
[Browsable(false )]
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Visible)]
public int ColumnID
{
get { return m_ColumnID; }
}
}
}

Sep 13 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2106
by: David K | last post by:
we are having a problem when trying to serilalize and deserialize DataTable When replacing the container to be ListArray or HashTable everything works fine The code is very straight forward ( see below), however when comparing the DataTable before and after the serialize, it is not the same The DataTable after the serialization contains only the string of class type ( Vclass in this class) but not the class itself Any idea ?
37
4990
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined signature. When developing this lib, I figured that the pointer-to-member-function, although seemingly an attractive solution, does not work well for us.
0
1234
by: ktn | last post by:
Hi all, I'm a .NET beginner and I've got a problem on a program where I try to do an XML serialization. I get the following error : "An unmanaged exception of type 'System.IO.FileNotFoundException' occured in mscorlib.dll Additonal information : the file or asssembly named n9gu4-bo.dll or one of its dependencies cannot be found"
1
4361
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have done this before but this time I have no idea why I am getting the error. Any ideas ?? THANKS ! <qcsttatus> <manual sourcerootfolder="" manualname="">
2
2352
by: ofer | last post by:
Hi, I am working with the beta version of the new .net framework (Whidbey) and I encountered a problem with serialization that did'nt exist in the .net 2003 the situation is like this : I have a class that inherits from dataset, and I want to serialize it , so I created a serialization constructor that forwards the call to the base class (the dataset) serialization constructor, normally, for this action to succeed I am supposed to put...
0
2492
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem serializing the object but there seems to be a problem serializing an array of objects. Any help will be appreciated "Cannot assign object of type System.Object to an object of type ElectronicWallet.C2PTest.PaymentItem." :...
2
1624
by: Norman Chong | last post by:
Hiddeldi ho, I want to save an object so that I can use its content after I restart my program. I tried to solve this with serialization because someone told me that this is the correct way for this. So I wrote the following code to serialize\deserialize the object, but now I have the problem that the object has a generic list and when I'm trying to deserialize it, I get an error. <System.Serializable()Public Class TestClass
4
11407
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I look at innerException it says: "Cannot serialize member 'System.ComponentModel.Component.Site' of type 'System.ComponentModel.ISite'. OK it is problem to serialize all data so I'll implement my Serialization. I implemented ISerializable...
2
5560
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as I am trying to read from a binary archive using Boost serialization. I am new to this, and it is possible that I have not understood the usage. In the code below, the string "faultblock" seems to be causing the problem. The code crashes in the ia...
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.