473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Serialization Problem - REPOST - PLEASE PLEASE HELP!

I posted this last week, but didn't get any reply. I'm trying again now,
because I'm getting desperate - I've tried everything I can think of myself.
PLEASE help somebody.

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, ColumnHeaderCollection and ColumnHeaderItem is supplied below. Can
anybody tell me what's wrong?

I've got a small test project (C# 2005) that I've stripped of everything but
the important part (the collection) - I cannot get the serialization to
work. I add columns at designtime, but no matter what, the columns are not
persisted to runtime. If anybody has got the time to help me, I can mail the
test project. I would REALLY appreciate any help.

Cheers, Johnny J.

public class MyListViewColumnConverter : TypeConverter
{
public override bool CanConvertTo
(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo
culture, object value, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor) && value is
MyListViewColumn)
{
MyListViewColumnitem = (MyListViewColumn)value;
ConstructorInfo ci = typeof(MyListViewColumn).GetConstructor(new Type[]
{ });
if (ci != null)
{
return new InstanceDescriptor(ci, null, false);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}

************************************************** ********
Listview, ColumnheaderCollection, ColumnHeaderItem code:
namespace MyListView
{
public class MyListView : ListView
{
private MyColumnHeaderCollection myListViewColumnHeaders = null;
public MyListView()
{
myListViewColumnHeaders = new MyColumnHeaderCollection(this);
//Other Code
}
public MyListView(IContainer container)
{
myListViewColumnHeaders = new MyColumnHeaderCollection(this);
container.Add(this);
//Other Code
}
[Localizable(true)]
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
[Editor("System.Windows.Forms.Design.ColumnHeaderCo llectionEditor,
System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[MergableProperty(false)]
public new MyColumnHeaderCollection Columns
{
get { return myListViewColumnHeaders; }
}
//Other Code
}
[DesignTimeVisible(false)]
public class MyColumnHeaderCollection : ListView.ColumnHeaderCollection
{
private SortedList columnList = new SortedList();
public new MyListViewColumn this[int index]
{
get
{ return (MyListViewColumn)columnList.GetByIndex(index); }
}
public override ColumnHeader Add(string str, int width, HorizontalAlignment
textAlign)
{
MyListViewColumn column = new MyListViewColumn(str, width, textAlign);
this.Add(column);
return column;
}
public override int Add(ColumnHeader column)
{
return this.Add(new MyListViewColumn(column));
}
public override void AddRange(ColumnHeader[] values)
{
for (int index = 0; index < values.Length; index++)
{
this.Add(new MyListViewColumn(values[index]));
}
}
public int Add(MyListViewColumn column)
{
int retValue = base.Add(column);
columnList.Add(column.ColumnID, column);
return retValue;
}
public new void Remove(ColumnHeader column)
{
base.Remove(column);
columnList.Remove(((MyListViewColumn)column).Colum nID);
}
public new void RemoveAt(int index)
{
ColumnHeader column = this[index];
this.Remove(column);
}
public new void Clear()
{
base.Clear();
columnList.Clear();
}
}
[DesignTimeVisible(false)]
[TypeConverter(typeof(MyListViewColumnConverter))]
public class MyListViewColumn : ColumnHeader
{
private int m_ColumnID = 0;
private static int autoColumnID = 0;
public MyListViewColumn()
{
Initialize("", 60, HorizontalAlignment.Left);
}
public MyListViewColumn(string str, int width, HorizontalAlignment
textAlign)
{
Initialize(str, width, textAlign);
}
public MyListViewColumn(ColumnHeader column)
{
Initialize(column.Text, column.Width, column.TextAlign);
}
private void Initialize(string str, int width, HorizontalAlignment
textAlign)
{
base.Text = str;
base.Width = width;
base.TextAlign = textAlign;
m_ColumnID = autoColumnID++;
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Visible)]
public int ColumnID
{
get { return m_ColumnID; }
}
}
}
Sep 17 '07 #1
0 1270

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

Similar topics

3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
5
by: Arjen | last post by:
Hello, Can somebody help me a little bit? I can't get it to work. Please see my code below... I have placed some comments like "// And whats next?". I'm sure that I have to code something...
1
by: Opa | last post by:
Hi I'm having problem serialization an object instance which contains a public property on the object type My object hierarchy is many levels deep, so for simplicty I created to following which...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
1
by: Joannes Vermorel | last post by:
I am having a serialization problem with a simple piece of code (short & complete) available at http://www.vermorel.com/opensource/NGridBugDemo.cs . When I run this code, I get a...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
2
by: Maximus | last post by:
Hi Everyone, I was using Inprocess session objects, but incase of aspnet process crashes the session objects were lost as a result I decided to shift to out of porocess session objects. For this...
8
by: =?Utf-8?B?UGlnZ3k=?= | last post by:
Hi to all, I am getting this System.OutOfMemoryException calling the Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(<stream>,<Obj>) method. The type of <streamis...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.