• DevExpress插件中GridView控件界面显示风格的保存与加载


    插件版本:

      DXperience_v9.3

    应用场景:

      界面需要显示数据库某表或视图数据,字段较多,列宽为默认值,显示顺序为默认顺序。

      用户在第一次使用软件时,把数据表格的显示风格全部重新调整了一番,并希望下次打开软件时显示自己设置的风格。

      当然,我们也要考虑到用户在设置后不满意,希望恢复到原始风格。

    设计思路:

      1、在窗体Load事件中,进行原始风格的保存操作;

      2、在窗体FormClosing事件中,进行当前风格的保存操作;

      3、在(右键)菜单中提供:保存风格、恢复风格的选项。

    实现方法:

      关键:DevExpress.XtraGrid.Views.Grid.GridView控件提供如下两个函数:

      ①SaveLayoutToXml (string xmlFile)

      ②RestoreLayoutFromXml (string xmlFile)

      细节:

      分析可知,保存风格及恢复风格都分为2类:原始风格、自定义风格

      于是在编写函数时就要根据不同的类别进行xml文件名的区分,此处为原始风格添加了前缀“Original_”

      代码:

            /// <summary>
            /// 程序运行的根路径
            /// </summary>
            private string m_BathPath = System.Environment.CurrentDirectory;
            
            //窗体加载事件:先保存原始风格,再加载自定义风格
            private void Form1_Load(object sender, EventArgs e)
            {
                this.SaveFormStyleXML(true);//保存原始风格
                this.LoadFormStyleXML(false);//加载自定义风格
            }
    
            //窗体关闭前事件:保存自定义风格
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                this.SaveFormStyleXML(false);//保存自定义风格
            }
            
            //Btn保存风格
            private void btnSaveStyle_Click(object sender, EventArgs e)
            {
                this.SaveFormStyleXML(false);//保存自定义风格
            }
    
            //Btn还原风格
            private void btnRestoreStyle_Click(object sender, EventArgs e)
            {
                this.LoadFormStyleXML(true);//加载原始风格
            }
            
            /// <summary>
            /// 保存界面风格
            /// </summary>
            private void SaveFormStyleXML(bool p_IsOriginal)
            {
                //XML文件保存目录
                string dirPath = m_BathPath + "\\config\\";
                //检查XML保存目录是否存在,若不存在则新建
                if (!System.IO.Directory.Exists(dirPath))
                {
                    System.IO.Directory.CreateDirectory(dirPath);
                }
                //若为原始风格,需加前缀Original_
                if (p_IsOriginal)
                {
                    dirPath += "Original_";
                }
                //保存GridView显示风格
                string fullPath = dirPath + "gdvStyle.xml";
                this.gridView1.SaveLayoutToXml(fullPath);
            }
            
            /// <summary>
            /// 加载界面风格
            /// </summary>
            private void LoadFormStyleXML(bool p_IsOriginal)
            {
                //XML文件保存目录
                string dirPath = m_BathPath + "\\config\\";
                //若为原始风格,需加前缀Original_
                if (p_IsOriginal)
                {
                    dirPath += "Original_";
                }
                //加载GridView显示风格
                string fullPath = dirPath + "gdvStyle.xml";
                if (System.IO.File.Exists(path_QueryYY))
                {
                    this.gridView1.RestoreLayoutFromXml(fullPath);
                }
            }
  • 相关阅读:
    运用jQuery实现动态点赞
    $scope作用及模块化解决全局问题
    angular数据绑定---js全局学习
    HDU 2102 A计划 (深搜)
    ffmpeg 常用命令汇总
    基于Red5与ffmpeg实现rtmp处理NVR或摄像头的监控视频处理方案
    Linux 下编写.sh文件运行JAR下的Class
    如何帮助团队完成一个优秀的API文档,Swagger和Spring Rest Docs两个都是十分优秀的工具!...
    你关心的学历问题在这里
    北京一二线大厂以及程序员层级分布
  • 原文地址:https://www.cnblogs.com/ExDevilLee/p/3446838.html
Copyright © 2020-2023  润新知