Solved

Serialization Deserialization Control property

Posted on 2010-09-10
7
702 Views
Last Modified: 2013-12-17
Serialization / DeSerialization Question

Experts,

Why can`t I serialize, Something like this? What's the work around?

public string TBoxStr
{
     get
          {
              return textbox1.text;
          }
      set
         {
            textbox1.text = value;
         }
}

I tried something like this too, and it doesn`t work.

private string tboxstr;
public string TBoxStr
{
     get
          {
             tboxstr = textbox1.text;
              return tboxstr;
          }
      set
         {
            tboxstr = value
            textbox1.text = tboxstr;
         }
}

I have no problem Serializing and Deserializing something like this -
private string property;
public string Property
{
     get
          {
              return property;
          }
      set
         {
            property = value
         }
}

I was hoping I could Serialize TBoxStr. What am I missing here?
0
Comment
Question by:San24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 6

Assisted Solution

by:tikusbalap
tikusbalap earned 75 total points
ID: 33651345
Try:

private string tboxstr;
public string TBoxStr
{
     get { return textbox1.Text; }
     set {  tboxstr = value; }
}

Set the tboxstr to your textbox after Form's load event.

private void form_load(object sender, EventArgs e)
{
    textbox1.Text = tboxstr;
}


0
 
LVL 3

Expert Comment

by:vusov
ID: 33652346
Do you try to serialize your Form? Actually it cannot be serialized because System.ComponentModel.Component.Site is not serializable. I'v tried to create some other class with TextBox and it serialized fine. Please review my sample, is it exactly what you mean?
WindowsFormsApplication2.zip
0
 

Author Comment

by:San24
ID: 33663115
For some reason I cant seem to upload the compressed project here. I`m getting a SUO file not allowed message. Anyways, here is the main form and the User Cntrl. I`m trying to Serialize and DeSerialize the textbox field in the User Control UC. I can Serialize without any problems, I can look at the value in the file but I run into problems DeSerializing it.

Any help to get me out of this would be greatly appreciated!
Form1.cs
UC.cs
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 75 total points
ID: 33663620
I suggest you to create an intermediate class which will only be used to serialize/deserialize.

Pass an instance of this to Control, and pass out at the time of serializing.
0
 

Author Comment

by:San24
ID: 33663658
@Novice_Novie - The problem is not Serializing, the problem I`m having is the property getting the Text Box value. One way to do is using the Validating or the Leave events and then initializing the property. Not the most efficient way to do it since I have multiple controls on the User Control.
0
 
LVL 3

Accepted Solution

by:
vusov earned 350 total points
ID: 33663929
Please review attachments, it's worked fine for me. I found you missed InitializeComponent(); in the UC(SerializationInfo info, StreamingContext ctxt) constructor.
WindowsFormsApplication2.zip
0
 

Author Comment

by:San24
ID: 33664084
@vusov : You Sir are the man! I didn`t miss the InitializeComponent(), I just didn`t know that was to be used. Didn`t find it any of the examples out there. Let me try this on the main program and then assign the points. Thanks again!
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question