1.保存
if (!Directory.Exists(GridViewLayoutFilePath))//判断是否存在文件夹
{ Directory.CreateDirectory(GridViewLayoutFilePath); }
fileName = GridViewLayoutFilePath + this.Name + .cfg";//文件名,后缀名为cfg
((BandedGridView)gridView).SaveLayoutToXml(fileName);//Dev内置方法,详情可以参考官方文档
2.读取
if (gridView.GetType() == typeof(BandedGridView))//判断类型
{
fileName = GridViewLayoutFilePath + this.Name + .cfg"
if (System.IO.File.Exists(fileName))
{
((BandedGridView)gridView).RestoreLayoutFromXml(fileName);//Dev内置方法
}
}
else if (gridView.GetType() == typeof(UC_TreeList))
{
fileName = GridViewLayoutFilePath + this.Name + .cfg"
if (System.IO.File.Exists(fileName))
{
((UC_TreeList)gridView).RestoreLayoutFromXml(fileName);
}
}
else if (gridView.GetType() == typeof(GridView))
{
fileName = GridViewLayoutFilePath + this.Name + .cfg"
if (System.IO.File.Exists(fileName))
{
((GridView)gridView).RestoreLayoutFromXml(fileName);
}
}
我是小赖 ,一个学C#的混子