|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Serializing custom properties on a BindingList.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(cMyBindingList)) 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 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.) 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? Show quoteHide quote "Luke Zhang [MSFT]" <lukez***@online.microsoft.com> wrote in message news:ZubhOnxTGHA.5588@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.) > 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.)
Installation Error: Application validation did not succeed. Unable to continue
what is Xtreme Sample Database Data Source with ReportViewer DataGrid Custom Styles How display Result from sqlCommand select in the Datagridview Small bit of code from VB6 to VB.net - desperate need of help Multithreading and ActiveX BackgroundWorker and 'freezing' application set back ground image to stretch how to capture print message |
|||||||||||||||||||||||