• C# superGridControl 样式设置、加载数据、获取数据


    样式设置

    superGridControl1.PrimaryGrid.SelectionGranularity = SelectionGranularity.Cell; //设置选中样式  单元格、整列、单元格和整列
                superGridControl1.PrimaryGrid.MultiSelect = false; //设置是否可以选中多行
                superGridControl1.PrimaryGrid.RowDragBehavior = RowDragBehavior.None;
                superGridControl1.PrimaryGrid.EnableCellMerging = true;
                superGridControl1.PrimaryGrid.ShowRowGridIndex = true;//显示行号
                superGridControl1.PrimaryGrid.AllowRowHeaderResize = true;//允许调整行头的宽度
                superGridControl1.PrimaryGrid.ShowRowHeaders = false; //不允许显示行头
                superGridControl1.PrimaryGrid.EnableFiltering = true; superGridControl1.PrimaryGrid.EnableColumnFiltering = true;//让列头显示筛选图标
                superGridControl1.PrimaryGrid.RowHeaderIndexOffset = 1;//设置行号的开始值
                this.superGridControl1.PrimaryGrid.Filter.Visible = true;//显示Filter
                this.superGridControl1.PrimaryGrid.GroupByRow.Visible = true; //允许按列分组
              //  GridPanel panel = superGridControl1.PrimaryGrid; panel.SetGroup(panel.Columns["Period"]);//使用分组
              

    SPG.PrimaryGrid.ShowRowGridIndex = false;//设置行号
    SPG.PrimaryGrid.SelectionGranularity = SelectionGranularity.Row;
    SPG.BackColor = Color.FromArgb(8, 47, 76);//设置控件的整个背景颜色不包含显示内容
    SPG.PrimaryGrid.DefaultVisualStyles.GridPanelStyle.Background.Color1 = Color.FromArgb(8, 47, 76);
    SPG.PrimaryGrid.DefaultRowHeight = 0;
    SPG.PrimaryGrid.ShowRowHeaders = false;
    SPG.PrimaryGrid.AllowEdit = false;
    SPG.DefaultVisualStyles.ColumnHeaderStyles.Default.Background.Color1 = Color.FromArgb(8, 47, 76);//设置背景颜色紧紧加载的内容
    SPG.DefaultVisualStyles.ColumnHeaderStyles.Default.Background.Color2 = Color.FromArgb(8, 47, 76);//设置背景颜色紧紧加载的内容
    SPG.DefaultVisualStyles.ColumnHeaderStyles.Default.TextColor = Color.White; SPG.DefaultVisualStyles.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter;//设置列头文字居中问题

    加载数据

    未设置列的情况下直接绑定数据源

     DataRow DR = DTS.NewRow();
                DR["调研代码"] = "1";
                DR["调研序列"] = "2";
                DR["调研维度"] = "3";
                DR["维度说明"] = "4";
                DR["核算单元1"] = "5";
                DR["核算单元2"] = "6";
                DTS.Rows.Add(DR);
                superGridControl1.PrimaryGrid.DataSource = DTS;

    当然在绑定列的情况下 如下 也可以绑定数据源

                GridColumn col = new GridColumn();
                col = new GridColumn();
                col.Name = "调研代码";
                col.HeaderText = "调研代码";
                col.EditorType = typeof(GridLabelXEditControl);
                col.FilterMatchType = FilterMatchType.RegularExpressions;
                col.CellMergeMode = CellMergeMode.None;
                col.AutoSizeMode = ColumnAutoSizeMode.None;
                col.Visible = false;
                superGridControl1.PrimaryGrid.Columns.Add(col);
                col = new GridColumn();
                col.Name = "调研序列";
                col.HeaderText = "调研序列";
                col.EditorType = typeof(GridLabelXEditControl);
                col.FilterMatchType = FilterMatchType.RegularExpressions;
                col.CellMergeMode = CellMergeMode.None;
                col.AutoSizeMode = ColumnAutoSizeMode.None;
                superGridControl1.PrimaryGrid.Columns.Add(col);
                col = new GridColumn();
                col.Name = "调研维度";
                col.HeaderText = "调研维度";
                col.EditorType = typeof(GridLabelXEditControl);
                col.FilterMatchType = FilterMatchType.RegularExpressions;
                col.CellMergeMode = CellMergeMode.None;
                col.AutoSizeMode = ColumnAutoSizeMode.None;
                superGridControl1.PrimaryGrid.Columns.Add(col);
                col = new GridColumn();
                col.Name = "维度说明";
                col.HeaderText = "维度说明";
                col.EditorType = typeof(GridLabelXEditControl);
                col.FilterMatchType = FilterMatchType.RegularExpressions;
                col.CellMergeMode = CellMergeMode.None;
                col.AutoSizeMode = ColumnAutoSizeMode.None;
                superGridControl1.PrimaryGrid.Columns.Add(col);
                col = new GridColumn();
                col.Name = "核算单元1";
                col.HeaderText = "核算单元1";
                col.EditorType = typeof(GridLabelXEditControl);
                col.FilterMatchType = FilterMatchType.RegularExpressions;
                col.CellMergeMode = CellMergeMode.None;
                col.AutoSizeMode = ColumnAutoSizeMode.None;
                superGridControl1.PrimaryGrid.Columns.Add(col);
                col = new GridColumn();
                col.Name = "核算单元2";
                col.HeaderText = "核算单元2";
                col.EditorType = typeof(GridLabelXEditControl);
                col.FilterMatchType = FilterMatchType.RegularExpressions;
                col.CellMergeMode = CellMergeMode.None;
                col.AutoSizeMode = ColumnAutoSizeMode.None;
                superGridControl1.PrimaryGrid.Columns.Add(col);

          //一行行加载并设置样式 (这种方法比较灵活)

         

     if (DTmain.Rows.Count > 0)
                {
                    GridRow gr = null;
                    foreach (DataRow dr in DTmain.Rows)
                    {
                        gr = new GridRow(new object[] {
                                    (dr["操作名称"]??"").ToString().Trim(),
                                    (dr["反馈消息"]??"").ToString().Trim(),
                                    (dr["导入条数"]??"").ToString().Trim(),
                                     (dr["导入时间段起"]??"").ToString().Trim(),
                                      (dr["导入时间段止"]??"").ToString().Trim(),
                                       (dr["日志添加时间"]??"").ToString().Trim()
                                });
                        gr.CellStyles.Default.Font = new Font("微软雅黑", 11);
                        gr.CellStyles.Default.TextColor = Color.White;
                        SPG.PrimaryGrid.Rows.Add(gr);
                    }
                }

     supergridcontrol  样式附加

    SPG.DefaultVisualStyles.ColumnHeaderStyles.Default.Background.Color1 = Color.FromArgb(8, 47, 76);  //设置列的背景颜色
    SPG.DefaultVisualStyles.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter //设置单元格文本居中
    SPG.DefaultVisualStyles.CellStyles.Default.AllowWrap = Tbool.True;//可自动换行
    SPG.DefaultVisualStyles.CellStyles.Selected.AllowWrap = Tbool.True; 

    注意:设置单元格的相关属性一般CellStyles,行样式用rowStyle

    supergridcontrol 在样式上同比其他的控件更加美观,但是在加载速度上不如datageidview 该控件在追求样式的时候丢失了 数据加载速度。

    supergridcontrol.cellclik事件中删除所选行    IsDeleted = true;删除行信息,或者supertgridcontrol.PrimaryGrid.Rows.Remove(gr); 这种方式保险点,iddeleted貌似与样式稍微有点冲突,建议用第二种方式。

  • 相关阅读:
    DFS HDU 1518 Square
    输入初始单纯形表后的单纯形程序,线性规划 未写完
    奇数幻方 程序实现 C++,linux系统下的codeblocks写的,估计里面的清屏函数windows下不能被调用
    棋盘切割 DP POJ 1191
    POJ 3716 Cow Bowling 数字三角形 简单DP
    ZOJ 3703 Happy Programming Contest (01背包,稍微加点处理)
    SQL Server 2005 Analysis Services实践(二)
    SPGridView的使用增加自动生成的序列号
    SQL Server 2005 Analysis Services实践(一)
    [转帖]传说中的MOSS葵花宝典Office SharePoint Server 2007 Starter Guide
  • 原文地址:https://www.cnblogs.com/hanke123/p/9289496.html
Copyright © 2020-2023  润新知