S
Shan1986
Guest
Hi,
I have a class called "Project" i serialize project to xml with below code and works fine.
Public ProjectsList As New BindingList(Of Project)
Public Sub SerializeObj(obj As Object, ByVal path As String)
Dim xs As New System.Xml.Serialization.XmlSerializer(obj.GetType)
Dim w As New StreamWriter(path)
xs.Serialize(w, obj)
End Sub
and i initialize my application like this with bindingsource
BS_ProjectsList.DataSource = ProjectsList
DataGridView4.DataSource = BS_ProjectsList
After initialization i am trying to load serialized xml to ProjectsList like below
ProjectsList = deSerializeObj(ProjectsList, fPath)
Public Function deSerializeObj(obj As Object, ByVal path As String) As Object
Dim fs As FileStream = New FileStream(path, FileMode.Open)
Dim xs As New XmlSerializer(obj.GetType)
obj = CType(xs.Deserialize(fs), Object)
fs.Close()
Return obj
End Function
It runs but my datagrid view does not show any object information it is just blank. but i could count the objects, what am i doing wrong?
If i do it like below it works but i want to know why the method above does not update the bindingsource?
Dim ss As New BindingList(Of Project)
ss = deSerializeObj(ProjectsList, fPath)
For Each project As Project In ss
ProjectsList.Add(project)
Next
thanks
Continue reading...
I have a class called "Project" i serialize project to xml with below code and works fine.
Public ProjectsList As New BindingList(Of Project)
Public Sub SerializeObj(obj As Object, ByVal path As String)
Dim xs As New System.Xml.Serialization.XmlSerializer(obj.GetType)
Dim w As New StreamWriter(path)
xs.Serialize(w, obj)
End Sub
and i initialize my application like this with bindingsource
BS_ProjectsList.DataSource = ProjectsList
DataGridView4.DataSource = BS_ProjectsList
After initialization i am trying to load serialized xml to ProjectsList like below
ProjectsList = deSerializeObj(ProjectsList, fPath)
Public Function deSerializeObj(obj As Object, ByVal path As String) As Object
Dim fs As FileStream = New FileStream(path, FileMode.Open)
Dim xs As New XmlSerializer(obj.GetType)
obj = CType(xs.Deserialize(fs), Object)
fs.Close()
Return obj
End Function
It runs but my datagrid view does not show any object information it is just blank. but i could count the objects, what am i doing wrong?
If i do it like below it works but i want to know why the method above does not update the bindingsource?
Dim ss As New BindingList(Of Project)
ss = deSerializeObj(ProjectsList, fPath)
For Each project As Project In ss
ProjectsList.Add(project)
Next
thanks
Continue reading...