DevExpress控件GridControl使用 z
设置选中行的背景色、而不改变前景色。
EnableAppearanceFocusedCell = False, EnableAppearanceFocusedRow = False
private void gdvMarket_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
if (e.RowHandle == gdvMarket.FocusedRowHandle)
{ e.Appearance.BackColor=Color.CadetBlue;
;
}
}
单元格颜色的设置
//最低价颜色控制
DevExpress.XtraGrid.StyleFormatCondition lowPrice = new DevExpress.XtraGrid.StyleFormatCondition();
lowPrice.Column = LowPrice;
lowPrice.Appearance.ForeColor = Color.Red;
lowPrice.Appearance.Options.UseForeColor = true;
lowPrice.Condition = DevExpress.XtraGrid.FormatConditionEnum.Expression;
lowPrice.Expression = "[LowPrice] > [PrevPrice]";
this.gdvMarket.FormatConditions.Add(lowPrice);
//涨跌颜色控制
DevExpress.XtraGrid.StyleFormatCondition range = new DevExpress.XtraGrid.StyleFormatCondition();
range.Column = Range;
range.Appearance.ForeColor = Color.Red;
range.Appearance.Options.UseForeColor = true;
range.Condition = DevExpress.XtraGrid.FormatConditionEnum.Greater;
range.Value1 = ;
this.gdvMarket.FormatConditions.Add(range);
单元格字符格式化方式
this.gdvMarket.Columns["RangePercent"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
this.gdvMarket.Columns["RangePercent"].DisplayFormat.FormatString = "{0}%";
设置列背景色
this.gdvMarket.Columns["Amount"].AppearanceCell.BackColor = Color.AliceBlue;
this.gdvMarket.Columns["Amount"].AppearanceCell.Options.UseBackColor = true;
GridView右键菜单
一、添加右键菜单
1.在VS工具箱中的“菜单和工具栏”找到ContextMenuStrip控件,双击添加。
2.点击ContextMenuStrip右上方的小三角形,打开编辑项,可以添加菜单项。至于菜单点击事件,这里就不多说了。
3.选择gridControl(注意这里不是gridView的属性),在属性中可以找到ContextMenuStrip属性,设置成刚添加的ContextMenuStrip。
这样的话,运行起来右击表格就可以看到右键菜单了。
二、是否可用设置
在不同情况下,例如选中行的个数以及内容的不同,右键菜单的菜单项是否可用需要作出判断,
这里需要用到gridView的PopupMenuShowing这个事件。也就是在菜单出现之前用户点击右键之后,来判断一下选择了几行,从而决定菜单项是否可用。
private void gridView_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
{
//获取选择的行数
int select = gridView.SelectedRowsCount;
itemOpen.Enabled = false;
itemDelete.Enabled = false;
if(select == )
{
itemOpen.Enabled = true;
itemDelete.Enabled = true;
}
else if(select > )
{
itemDelete.Enabled =true;
}
}
实现拖拽多选
GridView可以通过Shift键或Ctrl键以及Ctrl+A快捷键实现多选,但是默认不支持拖拽多选,好像也没有设置的方法。这样虽然没什么问题,但是肯定会给用户带来不便。
首先要设置OptionsSelection中的MultiSelect为true,也就是允许多选,否则下面的一切都是浮云。
本文通过以下代码实现拖拉多选的功能,主要是编写MouseDown、MouseMove、MouseUp三个函数。
这里需要注意一下GridHitInfo,这个类可以根据x、y坐标获取该点在GridView中的相关信息,例如在哪行哪列哪个单元格内,或者是否在单元格里。
//用于记录,鼠标是否已按下
bool isMouseDown = false; //用于鼠标拖动多选,标记是否记录开始行
bool isSetStartRow = false; //用于鼠标拖动多选,记录开始行
private int StartRowHandle = -; //用于鼠标拖动多选,记录现在行
private int CurrentRowHandle = -; //用于实现鼠标拖动选择多行功能中的一个方法,对单元格区域进行选中
private void SelectRows(int startRow, int endRow)
{
if (startRow > - && endRow > -)
{
gridView.BeginSelection();
gridView.ClearSelection();
gridView.SelectRange(startRow, endRow);
gridView.EndSelection();
}
} //实现鼠标拖动选择多行 ,鼠标按下事件
private void gridView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = true;
}
} //实现鼠标拖动选择多行 ,鼠标移动时
private void gridView_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
GridHitInfo info = gridView.CalcHitInfo(e.X, e.Y);
//如果鼠标落在单元格里
if (info.InRow)
{
if (!isSetStartRow)
{
StartRowHandle = info.RowHandle;
isSetStartRow = true;
}
else
{
//获得当前的单元格
int newRowHandle = info.RowHandle;
if (CurrentRowHandle != newRowHandle)
{
CurrentRowHandle = newRowHandle;
//选定 区域 单元格
SelectRows( StartRowHandle, CurrentRowHandle);
}
}
}
}
} //实现鼠标拖动选择多行 ,鼠标放开时
private void gridView_MouseUp(object sender, MouseEventArgs e)
{
StartRowHandle = -;
CurrentRowHandle = -;
isMouseDown = false;
isSetStartRow = false;
}
修改列的背景色
DevExpress.XtraGrid.StyleFormatCondition cn;
cn = new DevExpress.XtraGrid.StyleFormatCondition(DevExpress.XtraGrid.FormatConditionEnum.Equal, GridView1.Columns["列名"], null, );
cn.Appearance.BackColor = Color.Red;
GridView1.FormatConditions.Add(cn);
cn = new DevExpress.XtraGrid.StyleFormatCondition(DevExpress.XtraGrid.FormatConditionEnum.Equal, GridView1.Columns["列名"], null, );
cn.Appearance.BackColor = Color.Green;
GridView1.FormatConditions.Add(cn);
这样,这列如果值为0则是红色,为1则是绿色
去除”Drag a Column Header Here To Group by that Column”

Views-OptionsView-ShowGroupPanel=False
禁用GridControl中列头的过滤器
过滤器如下图所示:
设置 Run Design->OptionsCustomization->AllowFilter 设置为:false
显示水平滚动条?
设置this.gridView.OptionsView.ColumnAutoWidth = false;
设置成一次选择一行,并且不能被编辑
this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
this.gridView1.OptionsBehavior.Editable = false;
this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
显示行号?
this.gridView1.IndicatorWidth = ;
//显示行的序号
private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle>=)
{
e.Info.DisplayText = (e.RowHandle + ).ToString();
}
}
让各列头禁止移动?
设置gridView1.OptionsCustomization.AllowColumnMoving = false;
让各列头禁止排序?
设置gridView1.OptionsCustomization.AllowSort = false;
禁止各列头改变列宽?
设置gridView1.OptionsCustomization.AllowColumnResizing = false;
设置单元格自动换行?
1.ColumnEdit 增加 MemoEdit
2.AppearanceCell-TextOptions- WordWrap
3.OptionsView RowAutoHeight
设置每一列对齐方式?
View-Appearance-Row-TextOptions-(HAlignment = Center, VAlignment = Center)
设置行只读属性?
GridView.OptionsBehavior-Editable(false)
DevExpress控件GridControl使用 z的更多相关文章
- DevExpress控件GridControl中的布局详解 【转】
DevExpress控件GridControl中的布局详解 [转] 2012-10-24 13:27:28| 分类: devexpress | 标签:devexpress |举报|字号 订阅 ...
- DevExpress控件-GridControl根据条件改变单元格(Dev GridControl 单元格着色)
DevExpress控件-GridControl根据条件改变单元格颜色,如下图: 解决办法:可以参考:http://www.cnblogs.com/zeroone/p/4311191.html 第一步 ...
- DevExpress控件-GridControl根据条件改变单元格/行颜色(Dev GridControl 单元格着色) z
DevExpress控件-数据控件GridControl,有时我们需要根据特定条件改变符合条件的行或者单元格颜色达到突出显示目的,现在动起鼠标跟我一起操作吧,对的,要达到这个目的您甚至都不用动键盘. ...
- DevExpress控件-- Gridcontrol合并表头
写在前面的话: 在园子里逛了有一段时间了,一直想写点东西,但苦于自己的水平有限,生怕写出来的东西浪费了读者的时间.楼主有幸参加了公司DevExpress控件的培训,独乐乐不如众乐乐,特附上Demo以飨 ...
- DevExpress控件-GridControl根据条件改变单元格/行颜色--转载
DevExpress控件-数据控件GridControl,有时我们需要根据特定条件改变符合条件的行或者单元格颜色达到突出显示目的,现在动起鼠标跟我一起操作吧,对的,要达到这个目的您甚至都不用动键盘. ...
- DevExpress控件学习总结 z
1.Navigation & Layout 1.1 Bar Manager 如果想在窗体或用户控件(user control)上添加工具条(bars)或弹出菜单(popup menus),我们 ...
- DevExpress 控件 GridControl常见用法
刚接触DevExpress第三方控件,把GridControl的常见用法整理一下,以供参考: 说明: gcTest GridControl gvText GridView //隐藏最上面的G ...
- DevExpress控件使用小结 z
.TextEditor(barEditItem)取文本 string editValue = barEditItem1.EditValue.ToString(); //错误,返回null string ...
- DevExpress控件 GridControl 单元格编辑 回车
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
随机推荐
- luogu1233 木棍加工
先排个序然后做最长上升子序列就行了. #include <algorithm> #include <iostream> #include <cstdio> usin ...
- tzcacm去年训练的好题的AC代码及题解
A - Tree UVA - 548 You are to determine the value of the leaf node in a given binary tree that is th ...
- 为什么在header 和 session 之前不能有输出
1.在header输出之前有输出内容的话,就会造成对header的错误理解(尽管现在已经能容错了),例如不是满足“keyword: value\n”的格式还好,直接错误了,但是满足“keyword: ...
- 【Luogu】P2657windy数(数位DP)
题目链接 正式迈入了数位DP的大门…… 心情激动 (看我立个flag,我如果专攻数位DP的话,到wc之前就会有秒数位DP蓝题的能力) 数位DP讲解链接 讲的非常详细,良心博客.比我写的博客加在一起还要 ...
- HDU——1106排序(istringstream的使用、STLvector练习)
排序 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- Eclipse + Apache Axis2 发布RESTful WebService(三)第一个程序Hello Axis2 !(未成功)
此路不通 Axis2发布SOAP WebService非常简单,建一个Dynamic Web Project,然后为它建一个Axis的Web Service(Tomcat7+JDK),就会生成Clas ...
- Windows cmd 生成目录结构 dir /b,tree /f,xcopy
>dir *.sh *.ksh *.java /s/b > list.txt >tree /f > list.txt >xcopy C:\folder\from_fold ...
- docker (centOS 7) 使用笔记1
1. docker配置 初次在安装完docker后,初始化配置 copy默认的docker.service后,重启服务,会在/etc/systemd/system/multi-user.target. ...
- ecs01初始化node环境
npm install 报错 > uglifyjs-webpack-plugin@ postinstall /opt/apps/iview-admin/node_modules/webpack/ ...
- TroubleShoot:网站设置找不到术语管理
在SharePoint站点中找不到“术语管理”这个链接功能. 解决方案: Enable-SPFeature -id “73EF14B1-13A9-416b-A9B5-ECECA2B0604C” -Ur ...