DotNetBar SuperGridControl控件

article/2025/10/21 7:45:52

1.添加表头

            sgc.PrimaryGrid.SelectionGranularity = SelectionGranularity.Row;//点击选中一行DevComponents.DotNetBar.SuperGrid.GridColumn gc = null;gc = new DevComponents.DotNetBar.SuperGrid.GridColumn("ID");sgc.PrimaryGrid.Columns.Add(gc);gc = new DevComponents.DotNetBar.SuperGrid.GridColumn("类型编码");sgc.PrimaryGrid.Columns.Add(gc);

2.添加数据 加一行

sgc.PrimaryGrid.Rows.Add(new GridRow(new object[] { "a", "b" }));//也就是加一个GrindRow对像 

 

3.设点击选中一行后 取第一行第一列的值

SelectedElementCollection col = sgc.PrimaryGrid.GetSelectedRows();//选中的行集合if (col.Count > 0){GridRow gr = (col[0] as GridRow);//把第一行转为GridRow fac.ID = int.Parse(gr.Cells[0].Value.ToString());//取第一列的Value转一下//等效于int id= int.Parse((sgc.PrimaryGrid.GetSelectedRows()[0] as GridRow).Cells[0].Value.ToString());}

 4.增加一个下拉框

 4.1

 

using DevComponents.DotNetBar.SuperGrid;
using System;
using System.Windows.Forms;namespace TestForm
{public partial class Form1 : Form{public Form1(){InitializeComponent();this.Load += Form1_Load;}private void Form1_Load(object sender, EventArgs e){GridColumn col = new GridColumn("这是一个下拉框");col.HeaderText = "这是一个下拉框";col.Name = "这是一个下拉框";col.AutoSizeMode = ColumnAutoSizeMode.DisplayedCells;col.EditorType = typeof(DefineGridCB);col.EditorParams = new object[] { new object[] { "第一个", "第二个" } };superGridControl1.PrimaryGrid.Columns.Add(col);}//自定义控件public class DefineGridCB : GridComboBoxExEditControl{public DefineGridCB(object source){DataSource = source;}}//增加一行private void buttonItem1_Click(object sender, EventArgs e){superGridControl1.PrimaryGrid.NewRow(true);}}
}

View Code

  4.2 方法二 上边不传值 直接给一个无参构造方法

  public class ThisGridComboBoxControl : GridComboBoxExEditControl{public ThisGridComboBoxControl(){CustomList cl = new CustomList("BSC201Compare"); DataTable dt = cl.GetList();//这里我是执行了一个sql查询 有符号和名称两个列 反回一个dataTableDataSource = dt;DisplayMember = "名称";ValueMember = "符号";DropDownStyle = ComboBoxStyle.DropDownList;DropDownColumns = "名称|符号";MaxDropDownItems = 8;}}

4.2效果 

 

5.增加一个按钮

 

using DevComponents.DotNetBar.SuperGrid;
using System;
using System.Windows.Forms;
using DevComponents.DotNetBar.SuperGrid.Style;namespace TestForm
{public partial class Form1 : Form{public Form1(){InitializeComponent();this.Load += Form1_Load;}private void Form1_Load(object sender, EventArgs e){GridColumn col = new GridColumn("这是一个下拉框");col.HeaderText = "这是一个下拉框";col.Name = "这是一个下拉框";col.AutoSizeMode = ColumnAutoSizeMode.DisplayedCells;col.EditorType = typeof(DefineGridCB);col.EditorParams = new object[] { new object[] { "第一个", "第二个" } };superGridControl1.PrimaryGrid.Columns.Add(col);col = new GridColumn("这是一个按钮");col.AutoSizeMode = ColumnAutoSizeMode.DisplayedCells;col.EditorType = typeof(DefineGridButtonX);superGridControl1.PrimaryGrid.Columns.Add(col);}/// <summary>/// 自己定义按钮/// </summary>public class DefineGridButtonX : GridButtonXEditControl{public DefineGridButtonX(){this.Click += DefineGridButtonX_Click;}private void DefineGridButtonX_Click(object sender, EventArgs e){MessageBox.Show("1");}/// <summary>/// 控件属性/// </summary>/// <param name="cell"></param>/// <param name="style"></param>public override void InitializeContext(GridCell cell, CellVisualStyle style){base.InitializeContext(cell, style);this.Text = "这是一个按钮";}}//自定义下拉控件public class DefineGridCB : GridComboBoxExEditControl{public DefineGridCB(object source){DataSource = source;}}//增加一行private void buttonItem1_Click(object sender, EventArgs e){superGridControl1.PrimaryGrid.NewRow(true);}}
}

View Code

改变按钮颜色-依照别的列改变 在class的初始化中做如下操作

 public override void InitializeContext(GridCell cell, CellVisualStyle style){base.InitializeContext(cell, style);BackColor = Color.Transparent;//这个必须加上 不然也没有效果if ((EditorCell.GridRow["这是一个下拉框"].Value ?? "").ToString() != ""){unchecked{ForeColor = Color.FromArgb(255, 135, 206, 235);BackColor = Color.FromArgb(255, 135, 206, 235);}ColorTable = eButtonColor.Blue;}}

 

 

4~5效果

   

5.superGridControl一列变化 另一列自动加载对应的数据 判断一下值变货的单元格(后来看了看还是用cellClick会更好一些)

 private void SuperGridControl1_CellValueChanged(object sender, GridCellValueChangedEventArgs e){if (e.GridCell.GridColumn.Name == "下拉列"){superGridControl1.PrimaryGrid.Columns["下拉变动列"].EditorParams = new object[] { new object[] { "wf","HH"} };}}

 6.自动行高

SPG.PrimaryGrid.DefaultRowHeight = 0;

 7.去掉列头行头

            sgcCondition.SPG.PrimaryGrid.ShowColumnHeader = false;// sgcCondition.SPG.PrimaryGrid.ColumnHeader.Visible = false;//效果ms和上边一个样。。。sgcCondition.SPG.PrimaryGrid.ShowRowHeaders = false;

 8.选中行 默认选中首行

SPG.PrimaryGrid.SelectionGranularity = SelectionGranularity.Row;
SPG.PrimaryGrid.InitialSelection = RelativeSelection.Row;

 9.增加一行

 spgDetail.PrimaryGrid.NewRow(true);

10.删除选中行

SelectedElementCollection lstGR = spgDetail.PrimaryGrid.GetSelectedRows();if (lstGR != null)if (lstGR.Count > 0){foreach (GridRow gr in lstGR){spgDetail.PrimaryGrid.Rows.Remove(gr);}}

11.显示行号 且从1开始

SPG.PrimaryGrid.ShowRowGridIndex = true;
SPG.PrimaryGrid.RowHeaderIndexOffset=1;

 12.交换两行数据 实现上移下移

 

public static object[] GetRowValues(GridContainer gcRow){object[] obj = new object[(gcRow as GridRow).Cells.Count];for (int i = 0; i < (gcRow as GridRow).Cells.Count; i++){obj[i] = (gcRow as GridRow)[i].Value;}return obj;}/// <summary>/// 上、下移动表格行 /// </summary>/// <param name="spg"></param>/// <param name="gr"></param>/// <param name="isUp"></param>public static bool MoveSPGRow(SuperGridControl spg, bool isUp = true){var atRow = spg.PrimaryGrid.ActiveRow;if (atRow == null){PublicProperties.ShowInformation("请先选中要移动的行", AlertImage.Alert, 2000);//这里是个吐司函数就是提示一下return false;}object[] objRow = GetRowValues(atRow);if (isUp){if (atRow.RowIndex == 0){PublicProperties.ShowInformation("已经是第一行了,无法再向上移动", AlertImage.Alert, 2000);//这里是个吐司函数就是提示一下return false;}var atTop = spg.PrimaryGrid.Rows[atRow.RowIndex - 1];object[] objTop = GetRowValues(atTop as GridRow);spg.PrimaryGrid.Rows[atRow.Index - 1] = new GridRow(objRow);spg.PrimaryGrid.Rows[atRow.Index] = new GridRow(objTop);spg.PrimaryGrid.SetActiveRow(spg.PrimaryGrid.Rows[atRow.Index - 1] as GridRow);spg.PrimaryGrid.SetSelected(spg.PrimaryGrid.Rows[atRow.Index] as GridRow, false);}else{if (atRow.RowIndex == spg.PrimaryGrid.Rows.Count - 1){PublicProperties.ShowInformation("已经是最后一行了,无法再向下移动", AlertImage.Alert, 2000);//这里是个吐司函数就是提示一下return false;}var atBottum = spg.PrimaryGrid.Rows[atRow.RowIndex + 1];object[] objBottum = GetRowValues(atBottum as GridRow);spg.PrimaryGrid.Rows[atRow.Index + 1] = new GridRow(objRow);spg.PrimaryGrid.Rows[atRow.Index] = new GridRow(objBottum);spg.PrimaryGrid.SetActiveRow(spg.PrimaryGrid.Rows[atRow.Index + 1] as GridRow);spg.PrimaryGrid.SetSelected(spg.PrimaryGrid.Rows[atRow.Index] as GridRow, false);}return true;}}

View Code

 13.编辑superGridCell时 焦点没离开cell 点不失焦点的控件 如bar的buttonItem 那么cell里的值不会变,这里可用SetActive()函数 使焦点离开cell

SPG.PrimaryGrid.SetActive(false)

 14.选中行自动行高

        /// <summary>/// 只对选中行自动行高/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void SPG_RowActivated(object sender, GridRowActivatedEventArgs e){GridRow newrow = e.NewActiveRow == null ? new GridRow() : (e.NewActiveRow as GridRow);GridRow oldrow = e.OldActiveRow == null ? new GridRow() : e.OldActiveRow as GridRow;newrow.RowHeight = 0;if (newrow != oldrow){oldrow.RowHeight = 21;//原始宽度}}

 15.superGrid 实现选中区域上下填充

/// <summary>/// 实现superGridControl选中区上下填充/// </summary>/// <param name="isDown">true 向下 false 向上</param>/// <param name="isFolowCursor">true激活行跟随 false 不跟随</param>private static void FillCells(SuperGridControl SPG, bool isDown = true, bool isFolowCursor = true){//var cellSel = spgData.SPG.GetSelectedCells();//if (cellSel != null)//{//}var cellSel = SPG.GetSelectedCells();if (cellSel == null){return;}int iFirst = (cellSel.First() as GridCell).RowIndex;int iEnd = (cellSel.Last() as GridCell).RowIndex;GridRow grFirst = SPG.PrimaryGrid.Rows[iFirst] as GridRow;GridRow grEnd = SPG.PrimaryGrid.Rows[iEnd] as GridRow;for (int j = iFirst; j <= iEnd; j++){GridRow gr = SPG.PrimaryGrid.Rows[j] as GridRow;GridRow grTmp = null;if (isDown)grTmp = grFirst;elsegrTmp = grEnd;for (int i = 0; i < SPG.PrimaryGrid.Columns.Count; i++){if (gr[i].IsSelected && gr[i].AllowEdit == true){gr[i].Value = grTmp[i].Value;}}if (isFolowCursor)gr.SetActive();}if (isFolowCursor)grFirst.SetActive();}

 

 16.superGridControl出现滚动条时 追加数据 始终显示最后一条

//SPG.PrimaryGrid.ScrollToBottom()//这个不知为什么不行 看意思好像行的样子
//如果对spg有其他操作要刷新一下 spg.Refresh()不刷新下边的代码将不起作用
SPG.PrimaryGrid.LastOnScreenRowIndex = (SPG.PrimaryGrid.Rows.Last() as GridRow).Index;

 17.superGridControl 列的数据居中对齐

spgLoginInfo.DefaultVisualStyles.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter;

18.改变列头颜色

 spgLoginInfo.DefaultVisualStyles.ColumnHeaderStyles.Default.Background.Color1 = Color.FromArgb(8, 47, 76);spgLoginInfo.DefaultVisualStyles.ColumnHeaderStyles.Default.Background.Color2 = Color.FromArgb(8, 47, 76);

 19.superGridControl透明

            //整体透明superGridControl1.BackColor = Color.Transparent;//面板透明superGridControl1.DefaultVisualStyles.GridPanelStyle.Background.Color1= Color.Transparent;//行透明superGridControl1.DefaultVisualStyles.RowStyles.Default.Background.Color1 = Color.Transparent;//单元格透明superGridControl1.DefaultVisualStyles.CellStyles.Default.Background.Color1 = Color.Transparent;//改变单个单元格颜色(superGridControl1.PrimaryGrid.Rows[0] as GridRow).Cells[0].CellStyles.Default.Background.Color1 = Color.Red;    

http://chatgpt.dhexx.cn/article/yxpJHtnN.shtml

相关文章

DotNetBar第三方控件详解

DotNetBar是一款性价比很强的界面控件&#xff0c;带有56个Windows Form 控件的工具箱&#xff0c;使开发人员可以轻而易举地创建出专业美观的Windows Form应用程序用户界面&#xff0c;控件全部采用C#编写&#xff0c;引入了全部Office 2007 style Ribbon控件、Office 2003 of…

C#界面控件DotNetBar使用详解

一般来说&#xff0c;运用传统的界面控件元素&#xff0c;合理设计布局&#xff0c;能够设计出比较中规中矩的标准界面&#xff1b;利用一些换肤的控件或者部分界面组件&#xff0c;能够设计出相对好看一些的界面效果&#xff0c;如以前很盛行的ActiveSkin、IrisSkin和DotNetSk…

DotNetBar 14.1.X 安装+源码=不错选择

DotNetBar官方版是一款功能强大的UI桌面控件套包&#xff0c;能为用户提供了海量的控件&#xff0c;能够完美兼容Visual Studio 2005-2019等版本&#xff0c;为用户的开发工作提供了帮助。软件提供了工具栏、滑动面板、功能区超级菜单等功能&#xff0c;满足用户的各种开发控件…

DotNetBar教程

DotNetBar是一组用于.NET Framework环境下的一组组件集&#xff0c;利用该组件集能够打造绚丽并且实用的应用程序界面&#xff0c;给开发人员提供极大的便利。关于DotNetBar&#xff0c;详情请参考其官方网站&#xff1a;http://www.devcomponents.com 该组件集目前最新版本是8…

DotNetBar 介绍

DotNetBar是一款带有56个Windows Form 控件的工具箱&#xff0c;使开发人员可以轻而易举地创建出专业美观的Windows Form应用程序用户界面&#xff0c;控件全部采用C#编写&#xff0c;引入了全部Office 2007 style Ribbon控件、Office 2003 office2010 样式、支持windows7,Wind…

怎么用电脑设置让wifi变快

1.单击“开始——运行”&#xff08;也可用快捷键WinR&#xff09;打开&#xff0c;输入gpedit.msc确定后即可打开“组策略对象编辑器” 2.展依次点击“计算机配置→管理模板→网络→QoS数据包计划程序” 1&#xff0c;单击“开始——运行”&#xff08;也可用快捷键WinR&…

【wifi】一步提升无线网络上网速率

最近在做wifi芯片的干扰测试&#xff0c;测试项目包括同频干扰和邻频干扰。在实际测试中发现&#xff0c;同频干扰对无线网络的影响是相当大的&#xff0c;用chariot跑吞吐量&#xff0c;加两道干扰&#xff0c;没到干扰用chariot跑10条流&#xff0c;发现待测设备的吞吐量下降…

随身WiFi(棒子)折腾日记(不断更新完善...)

目录 随身WiFi&#xff08;棒子&#xff09;折腾日记&#xff08;不断更新完善...&#xff09;一、了解随身WiFi的版本情况二、确定需求剁手三、购买闭坑指南四、安装9008驱动五、系统备份1. MiKo备份2. 变砖拯救&#xff08;利用之前的备份镜像&#xff09;3. QPT 备份4. QCN&…

WIFI Direct/WIFI P2P

技术交流有兴趣请加: 音视频技术交流群:308601278 无线投屏技术交流群:582349005 本文可在找到相关详细内容 必捷网络|因必捷而简单 商务合作请至邮件marketingbijienetworks.com 上节说过了网卡的选型&#xff0c;之所以网卡的选型如此重要&#xff0c;主要是因为Mirac…

华为A1路由器设置虚拟服务器,华为a1路由器wifi定时加速功能的详细操作设置方法...

华为a1路由器怎么设置wifi定时加速功能呀。 很多新手不知道这款华为a1路由器不仅可以设置wifi限速&#xff0c;还能在“华为智能家居”APP上下载应用设置wifi按时加速&#xff0c;下面能哈小编将华为a1路由器wifi定时加速功能的详细操作设置方法分享一下&#xff0c;一起来看看…

全球WIFI功率(信号)最强的国家清单,无线WIFI调优

经常玩Merlin梅林或华硕路由器的朋友都知道&#xff0c;无线路由器有个国家地区选项&#xff0c;中文互联网中都在传说澳大利亚地区的无线信号最好&#xff0c;除了华硕这些全球品牌路由器厂商&#xff0c;还有网建Netgear、领势Linksys这些品牌也有调整路由器地区的功能&#…

提升Wi-Fi速率的方法有哪些

“ 上一篇文章以实例梳理和介绍了Wi-Fi的速率的情况&#xff0c;对比说明了真实速率和宣称速率的差别&#xff0c;这一篇文章将从技术的角度分析实际影响Wi-Fi传输速率的因素&#xff0c;以及对应的优化方法。” PHY&#xff08;物理层&#xff09;速率是一个理论极限速率&…

win10提高wifi速度

第一步&#xff1a;窗口键R打开 运行窗口 第二步&#xff1a;在窗口输入gpedit.msc ​ 如果没有打开&#xff0c;提示gpedit.msc找不到&#xff0c;按照以下做法&#xff1b;如果能打开直接继续第三步。 2.1&#xff1a;新建一个记事本&#xff0c; 2.2&#xff1a;然后在记事本…

vivo信号无服务器,vivo创新推出双WiFi网络加速功能,是否实用,聊胜于无!

原标题&#xff1a;vivo创新推出双WiFi网络加速功能&#xff0c;是否实用&#xff0c;聊胜于无&#xff01; “极客谈科技”&#xff0c;全新视角、全新思路&#xff0c;伴你遨游神奇的科技世界。 近期&#xff0c;vivo公布了一项较为特殊的技术&#xff0c;双WiFi网络加速功能…

Badboy下载安装超详细教程

一、下载安装包 Badboy安装包已经上传到百度云&#xff0c;有需要的同学可以关注微信公众号获取百度云密码&#xff0c;自行下载。 微信搜索公众号名称“那些美好深埋于心”或扫描文章结尾处二维码即可关注。 回复“Badboy”即可获得资源链接及密码。 二、Badboy安装 1.双…

BadBoy下载安装

1、简介 BadBoy是一款免费WEB自动化测试工具&#xff0c;其实就是一个浏览器模拟工具&#xff0c;具有录制和回放功能&#xff0c;支持对录制出来的脚本进行调试。同时支持捕获表单数据的功能&#xff0c;所以能够进行自动化测试。但目前用的多的是用来进行脚本录制&#xff0…

badboy无法录制 浏览器版本过低请下载最新的Badboy

badboy无法录制 浏览器版本过低请下载最新的Badboy 要参加软件测试大赛&#xff0c;性能测试需要badboy录制脚本。结果打开网页说我浏览器版本过低请下载最新的Chrome。我&#xff1a;&#xff1f;&#xff1f;&#xff1f;我默认浏览器可是Chrome啊怎么可能低。去网上查了下&a…

Jmeter+badboy自动化测试——Badboy基础操作

上接“Jmeterbadboy自动化测试——环境准备” 1. 启动 开Badboy&#xff0c;页面如下&#xff0c;录制按钮默认为开启&#xff0c;此时把badboy当做浏览器&#xff0c;进行的各种操作都会被badboy记录下载。 2. 记录 举个栗子&#xff0c;我在导航栏输入www.baidu.com&…

Badboy测试工具的使用教程

参考链接&#xff1a;https://blog.csdn.net/qq_28582847/article/details/80742054 https://www.cnblogs.com/UncleYong/p/10742653.html#_label0 https://blog.csdn.net/gantao754246624/article/details/79080025 Badboy工具介绍 Badboy是一个强大的工具&#xff0c;被设计…

Badboy

badboy 文章目录 badboy一、Badboy是什么二、Badboy能做什么三、Badboy怎么用&#xff08;1&#xff09;安装badboy&#xff08;2&#xff09;录制脚本&#xff08;3&#xff09;导出脚本&#xff08;4&#xff09;设置检查点&#xff08;5&#xff09;设置参数化-文本 报告 提…