Hey,
I am trying to use binary serialization to store data from a few textboxes, a few datagridviews and a chart with multiple series, but havent had much luck.
My current problem is that i'm trying to adapt an example to work with DGV's and I need to declare it. I have been trying to follow the format of the example.
Code:Imports System.IO Imports System.Runtime.Serialization Imports System.Runtime.Serialization.Formatters.Binary <Serializable()> _ Public Class bob Implements ISerializable Public Title As String = String.Empty Public Author As String = String.Empty Public Text As String = String.Empty Public texttest As String = String.Empty Public datagrid As DataGridView = 'find a way to store datagridviews Public Sub GetObjectData(ByVal info As SerializationInfo, _ ByVal context As StreamingContext) _ Implements ISerializable.GetObjectData info.AddValue("Title", Title) info.AddValue("Author", Author) info.AddValue("Text", Text) info.AddValue("TextTest", texttest) info.AddValue("datagrid", datagrid) End Sub Public Sub New(ByVal info As SerializationInfo, _ ByVal context As StreamingContext) Title = CStr(info.GetValue("Title", GetType(String))) Author = CStr(info.GetValue("Author", GetType(String))) Text = CStr(info.GetValue("Text", GetType(String))) texttest = CStr(info.GetValue("TextTest", GetType(String))) datagrid = (info.GetValue("datagrid", GetType(String))) End Sub Public Sub New() 'Empty Constructor End Sub Public Sub Serialize(ByVal Filename As String) Dim s As Stream Try s = File.Open(Filename, FileMode.Create, FileAccess.ReadWrite) Dim b As New BinaryFormatter b.Serialize(s, Me) Finally s.Close() End Try End Sub Public Shared Function Deserialize(ByVal Filename As String) As bob Dim s As Stream Try s = File.Open(Filename, FileMode.Open, FileAccess.Read) Dim b As New BinaryFormatter Return CType(b.Deserialize(s), bob) Finally s.Close() End Try End Function End Class
Not sure if its possible the way that i'm doing it, is there a better way? Possibly a way to serialize the entire program at once, and save it in its current state? That would be ideal.
Thanks![]()




Reply With Quote
