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

混江龙づ霸主 提交于 2020-08-05 11:38:19

样式设置

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貌似与样式稍微有点冲突,建议用第二种方式。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!