|
-
Oct 10th, 2012, 07:58 AM
#1
Thread Starter
Member
Binary Serialization of datagridview and chart tool
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
-
Oct 10th, 2012, 09:52 AM
#2
Re: Binary Serialization of datagridview and chart tool
Wait a minute.....where does the data in the DataGridView come from ? Data in controls should be considered disposable. Ie. They are for display purposes only and you should practice thinking in that way. What you should be doing is using the source of that data(before it reached the DataGridView) to save, edit, delete etc. You understand what I'm saying ?
-
Oct 10th, 2012, 10:33 AM
#3
Re: Binary Serialization of datagridview and chart tool
Completely agree with Niya. Here's a nice simple example showing a BindingList(Of T) being serialized/deserialized while having the list be the DataGridView's DataSource.
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
Oct 10th, 2012, 03:31 PM
#4
Thread Starter
Member
Re: Binary Serialization of datagridview and chart tool
I never thought of it that way. Currently the data is calculated, then added to the datagridview and then looped. I will look into Binding list(of T). Thank You both
Any ideas for the chart tool? Each series is generated from the data in the datagrids, if that helps.
-
Oct 10th, 2012, 03:45 PM
#5
Re: Binary Serialization of datagridview and chart tool
Here's the msdn documentation for serializing a chart. Pay attention to the section that talks about setting the Format to SerializationFormat.Binary as XML is the default.
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|