473,387 Members | 1,619 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,387 software developers and data experts.

Serializing custom properties on a BindingList.

I've created an object (called cMyBindingList) that inherits from
BindingList. I can serialize it and it's child items with no problem.
However, I've also created a public variable in cMyBindingList that I set
when I first create it. This variable, even though it is public, does not
serialize to the XML. What is the reason for this? Is it possible to do it?
TIA for any light you can shed. Here's the sample code (from a form with a
single button on it):

Imports System.ComponentModel

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oList1 As New cMyBindingList(15) '<-- note that iType is
specified
For i As Integer = 1 To 5 'Load up list
Dim oItem As New cMyItem
oItem.Value1 = i.ToString
oItem.Value2 = i.ToString
oList1.Add(oItem)
Next
Dim oSerializer As New
Xml.Serialization.XmlSerializer(GetType(cMyBinding List))
Dim myWriter As System.IO.StreamWriter = New
System.IO.StreamWriter("C:\MyTest.xml")
oSerializer.Serialize(myWriter, oList1)
End Sub
End Class

<Serializable()> <System.Runtime.InteropServices.ComVisible(False )> _
Public Class cMyBindingList
Inherits BindingList(Of cMyItem)
Public miMyType As Integer '<-- THIS DOES NOT SERIALIZE!
Public Sub New() 'this parameterless constructor required for
deserialization
End Sub
Public Sub New(ByVal iType As Integer)
miMyType = iType
End Sub
End Class

<Serializable()> <System.Runtime.InteropServices.ComVisible(False )> _
Public Class cMyItem
Private msValue1 As String
Private msValue2 As String
Public Property Value1() As String
Get
Return msValue2
End Get
Set(ByVal value As String)
msValue2 = value
End Set
End Property
Public Property Value2() As String
Get
Return msValue1
End Get
Set(ByVal value As String)
msValue1 = value
End Set
End Property
End Class
Mar 23 '06 #1
3 3896
Hello Monty,

BindingList class will be serialized as an array, its properties won't be
serialized. You may create a new class, add all customized properties in
this class, and then and cMyBindingList as a property of this new class.

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 24 '06 #2
Thanks for the response. Are there any collection-type objects that will
serialize both public properties on the container and the object's child
items?


"Luke Zhang [MSFT]" <lu******@online.microsoft.com> wrote in message
news:Zu**************@TK2MSFTNGXA01.phx.gbl...
Hello Monty,

BindingList class will be serialized as an array, its properties won't be
serialized. You may create a new class, add all customized properties in
this class, and then and cMyBindingList as a property of this new class.

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 27 '06 #3
I have to say there is a limitation here. The work around is to create a
parent class and move all public properties into the parent class.

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 28 '06 #4

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

Similar topics

1
by: Ivo Bronsveld | last post by:
All, I have quite a challenging task ahead of me. I need to write an object model (for code access) based on a schema, which cannot be made into a dataset because of it's complexity. So I...
2
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: +...
3
by: axr | last post by:
Having trouble with Serilization of objects that contain members which are of type Interface eg public class SomeClass { ISomeInterface1 itf1; ClassType1 ct1; ISomeInterface2 itf2;
0
by: g18c | last post by:
Hi, i have a class which has a property which is a list of items. I want to be able to set this item list from a set of items (in this case list2 as shown in the code below) from a drop down combo...
2
by: Merk | last post by:
I'm new to .NET (using 2.0) and was wondering how to go about binding a collection of custom classes to a DataGrid. The class exposes 5 read-only String properties. I would like for each of...
0
by: Pieter | last post by:
Hi, I'm using NHibernate 1.2 (CR1), and I'm using a custom list (inherited from BindingList(Of T) ) for all my lists. The NHibernate documentation told me that I had to implement...
3
by: jimmarq | last post by:
Please help me with this databinding scenario: Suppose I have a "Person" class, and that users populate Person objects in a BindingList collection through a datagridview. Users save the Person...
1
by: Karthik1979 | last post by:
I have a custom class inherited from List<T> collection. Along with the base class functionality, I have included my additional properties. When serializing, only the base class items are serialized...
5
by: Ben | last post by:
Does anyone have any example code showing how to sort a datagrid that is bound to a custom class array? My code calls a web method that returns an array of type LeadListDS. LeadListDS consists of...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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.