?
Solved

Serialization Deserialization Control property

Posted on 2010-09-10
7
Medium Priority
?
703 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 300 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 300 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 1400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 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