Solved

Serialization Deserialization Control property

Posted on 2010-09-10
7
701 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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