1:隐藏右上角的选择页面三角:controlbox-menubox-autohide  设置为false

2:设置某一单元的背景颜色:DG[c].CellStyles.Default.Background.Color1 = Color.Red;//如果列的类型是GridButtonXEditControl只会改变边框线颜色

public class SuperGridOP
{
//根据列分组
public static void SG_Group(SuperGridControl SGC,string colname)
{
GridPanel panel = SGC.PrimaryGrid;
panel.AutoExpandSetGroup = true;
if (colname == "")
{
panel.SetGroup();
}
else
{
panel.SetGroup(panel.Columns[colname], SortDirection.Descending);
}
SGC.Focus();
} //SuperGridControl控件初始化
public static void ResetLayout(SuperGridControl SGC)
{
GridPanel panel = SGC.PrimaryGrid;
GridColumnCollection columns = panel.Columns; for (int i = ; i < columns.Count; i++)
{
GridColumn col = columns[i]; col.Visible = false;
col.DisplayIndex = -; col.HeaderStyles.Default.Image = null;
col.HeaderStyles.Default.Background = null;
col.HeaderStyles.MouseOver.Background = null;
col.CellStyles.Default.Background = null;
}
panel.ColumnHeader.GroupHeaders.Clear();
panel.ClearAll();
SGC.PrimaryGrid.ColumnHeaderClickBehavior = ColumnHeaderClickBehavior.None;//表头点击没效果
} //设置控件属性
public static void SetSGCControl(SuperGridControl SGC)
{
//superGridControl1.PrimaryGrid.MaxRowHeight = 18;
SGC.PrimaryGrid.GroupHeaderHeight = ;//分组高度
SGC.PrimaryGrid.DefaultRowHeight = ;//行高
SGC.PrimaryGrid.ColumnHeader.RowHeight = ;//标题高度
// superGridControl1.PrimaryGrid.Columns["PrjLocation"].AutoSizeMode = ColumnAutoSizeMode.Fill;
SGC.PrimaryGrid.ExpandButtonType = ExpandButtonType.Triangle;//分组-树展开符号
SGC.PrimaryGrid.GroupHeaderClickBehavior = GroupHeaderClickBehavior.ExpandCollapse;//分组-展开
SGC.PrimaryGrid.MultiSelect = false;//不能选多行
SGC.PrimaryGrid.SelectionGranularity = SelectionGranularity.Row;//一次选中一整行
SGC.PrimaryGrid.RowWhitespaceClickBehavior = RowWhitespaceClickBehavior.ExtendSelection;//行空白区单击行为
SGC.PrimaryGrid.ShowGroupUnderline = false;
SGC.PrimaryGrid.ShowRowHeaders = false;// = 10;
SGC.DefaultVisualStyles.RowStyles.SelectedMouseOver =
SGC.BaseVisualStyles.RowStyles.Selected;//当控件宽度>列宽之和时 设置这个更好看
//设置表格中文字的位置居中
SGC.PrimaryGrid.DefaultVisualStyles.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter;
} //导出excel
public static System.Data.DataTable GetGridToDT(SuperGridControl SGC, string tbname)
{
System.Data.DataTable dt = new System.Data.DataTable(tbname);
Dictionary<string, string> diccol = new Dictionary<string, string>();//headertext-name
GridPanel gp = SGC.PrimaryGrid;
for (int i = ; i < gp.Columns.Count; i++)
{
GridColumn gc = gp.Columns[i];
if (gc.Visible)
{
dt.Columns.Add(gc.HeaderText);
diccol.Add(gc.HeaderText, gc.Name);
}
}
int rs = GetGridRowCount(SGC);
for (int i = ; i < rs; i++)
{
DataRow dr = dt.NewRow();
GridRow DG = GetGridRowByRowIndex(SGC, i);
DataRow drtag = DG.Tag as DataRow;
for (int j = ; j < dt.Columns.Count; j++)
{
string colname = dt.Columns[j].ColumnName;
dr[colname] = GetGridVal(SGC, i, diccol[colname]);
}
dt.Rows.Add(dr);
}
return dt;
} //根据行号获取GridRow对象
public static GridRow GetGridRowByRowIndex(SuperGridControl SGC, int r)
{
GridPanel gp = SGC.PrimaryGrid;
int startindex = ;
foreach (GridElement item in gp.Rows)
{
if (item is GridGroup)
{
GridGroup gg = item as GridGroup;
foreach (GridElement item1 in gg.Rows)
{
if (item1 is GridRow)
{
if (startindex == r)
{
return (GridRow)item1;
}
startindex++;
}
}
}
else if (item is GridRow)
{
if (startindex == r)
{
return (GridRow)item;
}
startindex++;
}
}
return null;
}
//获取所有行(如果有分组的情况,SGC.PrimaryGrid.Rows.Count获取行数得到的是组的个数)
private static int GetGridRowCount(SuperGridControl SGC)
{
GridPanel gp = SGC.PrimaryGrid;
int startindex = ;
foreach (GridElement item in gp.Rows)
{
if (item is GridGroup)
{
GridGroup gg = item as GridGroup;
foreach (GridElement item1 in gg.Rows)
{
if (item1 is GridRow)
{
startindex++;
}
}
}
else if (item is GridRow)
{
startindex++;
}
}
return startindex;
} //获取某行某列的单元格数据
private static string GetGridRowVal(GridRow DG, string cname)
{
string txt = "";
//获取某一单元格的值
object obj = DG[cname].Value;
obj = obj == null ? "" : obj;
txt = obj.ToString();
return txt;
}
private static string GetGridRowVal(GridRow DG, int c)
{
string txt = "";
//获取某一单元格的值
object obj = DG[c].Value;
obj = obj == null ? "" : obj;
txt = obj.ToString();
return txt;
} //获取某行某列的单元格数据
public static string GetGridVal(SuperGridControl SGC, int r, string cname)
{
// 获取某一行的信息
GridRow DG = GetGridRowByRowIndex(SGC, r);
return GetGridRowVal(DG,cname);
}
public static string GetGridVal(SuperGridControl SGC, int r, int c)
{
// 获取某一行的信息
GridRow DG = GetGridRowByRowIndex(SGC, r);// SGC.PrimaryGrid.Rows[r] as GridRow;
return GetGridRowVal(DG, c);
} //判断checkbox的值
public static bool GetGridVal_CK(SuperGridControl SGC, int r, int c)
{
// 获取某一行的信息
GridRow DG = GetGridRowByRowIndex(SGC, r);// SGC.PrimaryGrid.Rows[r] as GridRow;
string strval = GetGridRowVal(DG, c).ToUpper();
if (strval == "" || strval == "TRUE")
{
return true;
}
return false;
}
public static bool GetGridVal_CK(SuperGridControl SGC, int r, string cname)
{
GridRow DG = GetGridRowByRowIndex(SGC, r);// SGC.PrimaryGrid.Rows[r] as GridRow;
string strval = GetGridRowVal(DG, cname).ToUpper();
if (strval == "" || strval == "TRUE")
{
return true;
}
return false;
} //设置某行某列的单元格数据
public static void SetGridVal(SuperGridControl SGC, int r, int c, string val)
{
GridRow DG = GetGridRowByRowIndex(SGC, r);// SGC.PrimaryGrid.Rows[r] as GridRow;
DG[c].Value = val;
}
public static void SetGridVal(SuperGridControl SGC, int r, string cname, string val)
{
GridRow DG = GetGridRowByRowIndex(SGC, r);// SGC.PrimaryGrid.Rows[r] as GridRow;
DG[cname].Value = val;
} /// <summary>创建列
///
/// </summary>
/// <param name="name">列的name</param>
/// <param name="headertxt">列的title</param>
/// <param name="cwidth">列宽</param>
/// <param name="ctp">列的类型 0默认,1check框,2下拉框,3按钮</param>
/// <returns></returns>
public static GridColumn CreatNewCol(string name, string headertxt, int cwidth, int ctp)
{
GridColumn gc = new GridColumn();
gc.Name = name;
gc.HeaderText = headertxt;
//gc.ReadOnly = true;
gc.Width = cwidth;
//gc.CellMergeMode = CellMergeMode.Vertical;
//gc.AllowSelection = false;
//gc.AllowEdit = false;
if (ctp == )
{
gc.EditorType = typeof(DevComponents.DotNetBar.SuperGrid.GridCheckBoxXEditControl);//列的类型
}
else if (ctp == )
{
gc.EditorType = typeof(DevComponents.DotNetBar.SuperGrid.GridComboBoxExEditControl);//列的类型
}
else if (ctp == )
{
gc.EditorType = typeof(DevComponents.DotNetBar.SuperGrid.GridButtonXEditControl);//列的类型
}
if (cwidth < )
{
gc.AutoSizeMode = ColumnAutoSizeMode.Fill;
}
return gc;
} /// <summary>获取某列值为x所在行的另一列数据
///
/// </summary>
/// <param name="SGC"></param>
/// <param name="cname">要求的列</param>
/// <param name="cothername">已知数据的列</param>
/// <param name="cotherval">已知的数据</param>
/// <returns></returns>
public static string GetValByOtherColData(SuperGridControl SGC, string cname, string cothername, string cotherval)
{
string res = "";
int rs = GetGridRowCount(SGC);
if (rs < )
{
return res;
}
for (int i = ; i < rs; i++)
{
string val = GetGridVal(SGC, i, cothername);
if (val == cotherval)
{
res = GetGridVal(SGC, i, cname);
}
}
return res;
}
public static int GetRowIndexByOtherColData(SuperGridControl SGC, string cname, string cothername, string cotherval)
{
int res = -;
int rs = GetGridRowCount(SGC);
if (rs < )
{
return res;
}
for (int i = ; i < rs; i++)
{
string val = GetGridVal(SGC, i, cothername);
if (val == cotherval)
{
res = i;
break;
}
}
return res;
} //横的合并表头
public static ColumnGroupHeader GetAdContactHeader(GridColumnCollection columns, string str1, string str2, string title)
{
ColumnGroupHeader cgh = new ColumnGroupHeader(); cgh.MinRowHeight = ; cgh.Name = "titlename";
cgh.HeaderText = title;
cgh.AllowSelection = false; // Set the start and end Display Index which the
// group header is associated with. cgh.StartDisplayIndex = columns.GetDisplayIndex(columns[str1]);
cgh.EndDisplayIndex = columns.GetDisplayIndex(columns[str2]); return (cgh);
}
private ColumnGroupHeader GetAdContactHeader(int stc, int endc, string title)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.MinRowHeight = ;
cgh.Name = "titlename";
cgh.HeaderText = title;
cgh.AllowSelection = false;
cgh.StartDisplayIndex = stc;
cgh.EndDisplayIndex = endc;
return (cgh);
} #region 例子
//创建一个 3行 n列的表格头
public static void testsgc(SuperGridControl SGC)
{
//先建好列
GridPanel panel = SGC.PrimaryGrid; panel.MinRowHeight = ;
panel.Columns.Add(CreatNewCol("cs", "列0", , ));
panel.Columns.Add(CreatNewCol("jz1", "列1", , ));
panel.Columns.Add(CreatNewCol("jz2", "列2", , ));
panel.Columns.Add(CreatNewCol("jz3", "列3", , ));
panel.Columns.Add(CreatNewCol("jz4", "列4", , ));
panel.Columns.Add(CreatNewCol("jz5", "列5", , )); panel.Columns.Add(CreatNewCol("ds1", "列1", , ));
panel.Columns.Add(CreatNewCol("ds2", "列2", , ));
panel.Columns.Add(CreatNewCol("ds3", "列3", , ));
panel.Columns.Add(CreatNewCol("ds4", "列4", , )); panel.Columns.Add(CreatNewCol("dx1", "列1", , ));
panel.Columns.Add(CreatNewCol("dx2", "列2", , ));
panel.Columns.Add(CreatNewCol("dx3", "列3", , )); panel.Columns.Add(CreatNewCol("hmjr", "列1", , ));
panel.Columns.Add(CreatNewCol("hmujr", "列2", , ));
panel.Columns.Add(CreatNewCol("hm", "列3", , ));
GridColumnCollection columns = panel.Columns;
// ColumnGroupHeader cgh = GetIlAdditionalInfoHeader(columns);
//设置列头合并
ColumnGroupHeader c1 = GetAdContactHeader(columns, "jz1", "jz5", "组1");//
ColumnGroupHeader c2 = GetAdContactHeader(columns, "ds1", "dx3", "组2");
ColumnGroupHeader c3 = GetAdContactHeader(columns, "ds1", "ds4", "组3");
ColumnGroupHeader c4 = GetAdContactHeader(columns, "dx1", "dx3", "组4");
c2.GroupHeaders.Add(c3); c2.GroupHeaders.Add(c4); panel.ColumnHeader.GroupHeaders.Add(c1);
panel.ColumnHeader.GroupHeaders.Add(c2);
}
private void addrows(SuperGridControl SGC)
{
for (int i = ; i < ; i++)
{
GridRow Dfr = SGC.PrimaryGrid.NewRow();
Dfr[].Value = i;
Dfr[].Value = i;
Dfr[].Value = i;
SGC.PrimaryGrid.Rows.Add(Dfr);
}
}
#endregion }

WinForm控件--DotNetBar--SuperGridControl的更多相关文章

  1. 在WPF中使用WinForm控件方法

    1.      首先添加对如下两个dll文件的引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll. 2.      在要使用WinForm控 ...

  2. WPF 调用WinForm控件

    WPF可以使用WindowsFormsHost控件做为容器去显示WinForm控件,类似的用法网上到处都是,就是拖一个WindowsFormsHost控件winHost1到WPF页面上,让后设置win ...

  3. WinForm控件TreeView 只部分节点显示 CheckBox

    WinForm控件TreeView 只部分节点显示  CheckBox 用过asp.net的应该知道,要在treeview中实现上述功能可以使用ShowCheckBox 属性指定那些节点显示check ...

  4. Winform控件重写

    Winform控件重写 因为最近的项目中越来越多的遇到了比较特殊的一些控件,有时候我们自己封装一下可能更加方便我们的使用,下面是我们项目中用到的,简单做一个记录. TextBox控件重写 主要的控制代 ...

  5. 通过WinForm控件创建的WPF控件无法输入的问题

    今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在我的机器上却是好好的. 最开始以为是输入法的问题,弄了好一阵子 ...

  6. c#Winform控件总结

    1. C# WinForm控件.自定义控件整理(大全) (http://www.cnblogs.com/top5/archive/2010/04/29/1724039.html) 2. c#窗体控件用 ...

  7. 在WPF中调用Winform控件

    最近在项目中用到了人脸识别和指纹识别,需要调用外部设备和接口,这里就用到了在WPF中调用Winform控件. 第一步,添加程序集引用.System.Windows.Forms和WindowsForms ...

  8. C# 扩展方法奇思妙用高级篇六:WinForm 控件选择器

    在Web开发中,jQuery提供了功能异常强大的$选择器来帮助我们获取页面上的对象.但在WinForm中,.Net似乎没有这样一个使用起来比较方便的选择器.好在我们有扩展方法,可以很方便的打造一个. ...

  9. WinForm控件使用文章收藏整理完成

    对C# WinForm开发系列收集的控件使用方面进行整理, 加入了一些文章, 不断补充充实, 完善这方面. 基础 - 常用控件 C# WinForm开发系列 - CheckBox/Button/Lab ...

  10. [转]在WPF中使用WinForm控件方法

    本文转自:http://blog.csdn.net/lianchangshuai/article/details/6415241 下面以在Wpf中添加ZedGraph(用于创建任意数据的二维线型.条型 ...

随机推荐

  1. bash内建命令

    bash内建命令 1.local命令 基本介绍 local命令是用来定义一个局部变量的,它只能定义在函数中,并且随着函数的结束而被销毁 基本语法 local  [option]  name[=valu ...

  2. 对C语言指针的理解

    一个小程序引发对于C语言指针的思考: #include <bits/stdc++.h> using namespace std; void my_swap (int* a,int* b) ...

  3. 部署springboot工程到linux上及遇到的坑

    一.步骤 1.将工程打成jar包 IDEA中点击file-project structure,如下图: 选择Artifacts-JAR-From modules,选择入口类Main Class,如下图 ...

  4. MATLAB 进行五种边缘检测

    自定义函数: function []=edge_detect(image_name) a=imread(image_name); I=rgb2gray(a); BW1=edge(I,'Roberts' ...

  5. Flask开发遇到的问题:BuildError: Could not build url for endpoint 'main.followers' with values ['username']. Did you mean 'main.user' instead?

    @(Flask Web Development 12th chapter) 描述 Flask开发中遇到BuildError: Could not build url for endpoint 'mai ...

  6. Windows 上安装 Azure PowerShell及Azure PowerShell部署虚拟机

    一.Azure PowerShell部署   1.使用 PowerShellGet 在 Windows 上安装 Azure PowerShell 从 Azure PowerShell 版本 6.0 开 ...

  7. 前端的UI框架

    iView 框架 使用场景 iView 主要适合大中型中后台产品,比如某产品的运营平台.数据监控平台.管理平台等,从工程配置.到样式布局,甚至后面规划的业务套件,是一整套的解决方案,所以它可能不太适合 ...

  8. 关于在Servlet中的Fileter

    Servlet(Server Applet)是Java Servlet的简称,称为小服务程序或服务连接器,用Java编写的服务器端程序,具有独立于平台和协议的特性,主要功能在于交互式地浏览和生成数据, ...

  9. TCP建立与断开连接、socket通讯模板

    在传输层,有一个重点是TCP传输时建立连接的三次"握手"和四次"挥手",因为socket工作于应用层和传输层之间,故而涉及到建立连接和关闭连接的过程,以下笔记可 ...

  10. 矩形覆盖(JAVA)

    矩形覆盖 题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 思路:最初看到这题,只能通过画图归纳来寻找规律. ...