You would like to do something like this I suppose:
[Serializable]
public class Element
{
public int field1;
public string field2;
public Element()
{
}
public Element(int f1, string f2)
{
field1 = f1;
field2 = f2;
}
}
static void Serialize()
{
FileStream fs = new FileStream("DataFile.dat", FileMode.Create);
List<element> elements = new List<element>();
elements.Add(new Element(1,"One"));
elements.Add(new Element(2,"Two"));
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, elements);
}
catch (SerializationException e)
{
Console.WriteLine("Failed to serialize. Reason: " + e.Message);
throw;
}
finally
{
fs.Close();
}
}
Obviously you will have to create something better than my Element class, but if your create similar classes reflecting the properties of the form you can then bind to the elements through a BindingSource. I think this is basically what SAKryukov suggested :)
Regards
Espen Harlinn