using System.Runtime.Serialization.Formatters.Binary;if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    BinaryFormatter bf = new BinaryFormatter();
    bf.Serialize(this.saveFileDialog1.OpenFile(), object);
}

解决方案 »

  1.   

    上面这位兄台,先TKS, 但是请看清问题先,DataGridTableStyle是没有标记[Serialize]特性的.
      

  2.   

    写一个你的类,继承DataGridTableStyle
    然后把你的类标志为可序列化阿
    然后用你的类不就行了
      

  3.   

    自己写一个可序列化的类,保存DataGridTableStyle中的各属性的值.通过这个类间接的序列化DataGridTableStyle public class ObjectInfo:System.Runtime.Serialization.ISerializable
    {
    Hashtable infoTable;
    public ObjectInfo()
    {
    infoTable = new Hashtable();
    }
    #region ISerializable 成员 public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
    {
    // TODO:  添加 ObjectInfo.GetObjectData 实现
    } #endregion public void SaveInfo(object sourceObject)
    {
    Type type = sourceObject.GetType();
    System.Reflection.PropertyInfo[] propertyInfors = type.GetProperties();
    for(int i=0 ; i< propertyInfors.Length; i++)
    {
    System.Reflection.PropertyInfo propertyInfor = propertyInfors[i];
    infoTable.Add(propertyInfor.Name,propertyInfor.GetValue(sourceObject,null));
    }
    } public void GetInfo(object sourceObject)
    {
    Type type = sourceObject.GetType();
    System.Reflection.PropertyInfo[] propertyInfors = type.GetProperties();
    for(int i=0 ; i< propertyInfors.Length; i++)
    {
    System.Reflection.PropertyInfo propertyInfor = propertyInfors[i];
    if(infoTable.ContainsKey(propertyInfor.Name))
    {
    propertyInfor.SetValue(sourceObject,infoTable[propertyInfor.Name],null);
    }
    }
    }
    }
      

  4.   

    序列化DataGridTableStyle和DataGridColumnStyle类到XML中用XML Serialization不行吗?
    Binary Serialization和XML Serialization要求不一样的。
      

  5.   

    XML序列化只需要一个public无参数的构造函数和相关属性也遵循XML Serilaization的规则就行了。