• DevExpress WinForm嵌入子图、允许数据换行显示


    实现效果,可以通过前面的±号,选择是否展开。
    DevExpress嵌套表
    首现要将DevExpress需要显示的对象和子对象封装成类,在类中就定义为嵌套
    的形式

    internal class WarningDetail
        {
            public string Date { get; set; }
            public string Description { get; set; }
        }
    
        internal class WarningInfo
        {
            public string ID { get; set; }
            public string Date { get; set; }
            public string Warning { get; set; }
            public List<WarningDetail> Detail2List { get; set; }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    然后,绑定GridView的数据,表格的宽度按照需求设定

     private void TimeDataViewer(string[] list, DateTime _startTime, DateTime _endTime)
            {
                //为链接动作,需要将数据存储到队列并记录位置
                List<WarningInfo> warningInfoList = new List<WarningInfo>();           
               //数据处理部分省略
               
               //绑定数据
                this.TimeGridControl.DataSource = warningInfoList;
                
                //绑定子表
                 GridView grv2 = null;
                 //共用一个GridView和GridControl
                var grv = this.TimeGridView;
                var gridControl = this.TimeGridControl;
                //创建一个从表的GridView对象
                grv2 = new GridView();
                grv2.ViewCaption = "记录明细";
                grv2.Name = "grv2";
                grv2.GridControl = gridControl;
                //构建GridLevelNode并添加到LevelTree集合里面
                var node = new GridLevelNode();
                node.LevelTemplate = grv2;
                node.RelationName = "Detail2List";//这里对应集合的属性名称
                gridControl.LevelTree.Nodes.AddRange(new GridLevelNode[] { node });
                //添加对应的视图集合显示
                gridControl.ViewCollection.Clear();
                gridControl.ViewCollection.AddRange(new BaseView[] { grv, grv2 });
    
    
                this.TimeGridView.GroupPanelText = "异常统计(时间)";            
                this.TimeGridView.OptionsView.ShowGroupPanel = true;
                this.TimeGridView.OptionsView.EnableAppearanceOddRow = true;//奇数行颜色变化
                this.TimeGridView.Appearance.OddRow.BackColor = System.Drawing.Color.LightSteelBlue;//奇数行颜色设置  
                this.TimeGridView.OptionsView.EnableAppearanceEvenRow = true;//偶数行颜色变化
                this.TimeGridView.Appearance.EvenRow.BackColor = System.Drawing.Color.AliceBlue;//偶数行颜色设置
                this.TimeGridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.Click;//设置只能选中整行
                this.TimeGridView.OptionsBehavior.Editable = false;//设置列的数据不能编辑
                表格的宽度按照需求设定,例如我设置为123            this.TimeGridView.Columns[0].Width = this.TimeGridControl.Width/6;
                this.TimeGridView.Columns[1].Width = 2 * this.TimeGridControl.Width / 6;
                this.TimeGridView.Columns[2].Width = 3 * this.TimeGridControl.Width / 6;
            }
            //允许换行显示
    DevExpress.XtraEditors.Repository.RepositoryItemMemoEdit memoEdit = new DevExpress.XtraEditors.Repository.RepositoryItemMemoEdit();//创建RepositoryItemMemoEdit
                memoEdit.AutoHeight = true;
                this.TimeGridView.Columns[1].ColumnEdit = memoEdit;//允许第二行换行显示
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
  • 相关阅读:
    音频修复增强软件iZotope RX 10 mac中文特点
    Android Studio javadoc 编译的时候一直报错 java.lang.IllegalArgumentException
    R语言贝叶斯METROPOLIS-HASTINGS GIBBS 吉布斯采样器估计变点指数分布分析泊松过程车站等待时间...
    Python数学基础-识图一、平面直角坐标系
    【Flink】基本转换算子使用之fliter、flatMap,键控流转换算子和分布式转换算子
    Python-多线程基础(线程,锁,通讯,线程池)
    怎么将WPS转换成WORD?看完你就学会了
    VulnStack - ATT&CK红队评估实战(四) Writeup
    数据可视化设计经验分享,正确使用主题风格,打造专属数字大屏
    【Unity】VR开发基础1-工具准备-下载Unity
  • 原文地址:https://blog.csdn.net/weixin_40105418/article/details/127983138