Link to home
Start Free TrialLog in
Avatar of San24
San24

asked on

Serialization Deserialization Control property

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?
SOLUTION
Avatar of tikusbalap
tikusbalap
Flag of Indonesia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of San24
San24

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of San24

ASKER

@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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of San24

ASKER

@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!