樣式設置
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貌似與樣式稍微有點沖突,建議用第二種方式。