DevExpress 控件 GridControl常见用法
刚接触DevExpress第三方控件,把GridControl的常见用法整理一下,以供参考:
说明:
gcTest GridControl
gvText GridView
//隐藏最上面的GroupPanel 即去掉"Drag a Column Header Here To Group by that Column"
gvText.OptionsView.ShowGroupPanel = false;
//修改最上面的GroupPanel
gvText.GroupPanelText = "修改后的内容";
//单元格不可编辑
gvText.OptionsBehavior.Editable = false;
//某列标题居中 0是列索引
gvText.Columns[0].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
//某列内容居中 0是列索引
gvText.Columns[0].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
//冻结列
gvText.Columns[0].Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left;
//自动改变行高适应内容
gvText.OptionsView.RowAutoHeight = true;
//显示自动筛选行
gvText.OptionsView.ShowAutoFilterRow = false;
//不显示字表信息
gvText.OptionsView.ShowDetailButtons = false;
//显示水平滚动条,自动列宽
gvText.OptionsView.ColumnAutoWidth=false;
//自动调整列宽
gvText.BestFitColumns();
//禁用GridControl中单击列弹出右键菜单
gvText.OptionsMenu.EnableColumnMenu = false;
//禁用GridControl中列头的过滤器
gvText.OptionsCustomization.AllowFilter = false;
//禁止各列头移动
gvText.OptionsCustomization.AllowColumnMoving = false;
//禁止各列头排序
gvText.OptionsCustomization.AllowSort = false;
//禁止各列头改变列宽
gvText.OptionsCustomization.AllowColumnResizing = false;
//根据绑定的数据源自动产生列,有时可以解决GridControl记录能获取而没有显示出来的问题
gvText.PopulateColumns();
//奇偶行变色
gvText.OptionsView.EnableAppearanceEvenRow = true;
gvText.OptionsView.EnableAppearanceOddRow = true;
gvText.Appearance.EvenRow.BackColor = Color.Gray;
gvText.Appearance.OddRow.BackColor = Color.GreenYellow;
//特殊列设置 日期
string strDate="yyyy-MM-dd HH:mm";
RepositoryItemDateEdit ride = new RepositoryItemDateEdit();
ride.DisplayFormat.FormatString = strDate;
ride.EditFormat.FormatString = strDate;
ride.EditMask = strDate;
gvText.Columns["日期"].ColumnEdit = ride;
//列格式设置 decimal 价格
public const string MoneyFormatStr = "##,###,###,###,##0.00";
RepositoryItemCalcEdit rice = new RepositoryItemCalcEdit();
rice.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
rice.DisplayFormat.FormatString = MoneyFormatStr;
rice.EditFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
rice.EditFormat.FormatString = MoneyFormatStr;
rice.EditMask = MoneyFormatStr;
gv.Columns["价格"].ColumnEdit = rice;
//给单元格赋值
gvText.SetRowCellValue(3, gvText.Columns["列名或列索引"],"要赋的值");
//添加行
gvText.AddNewRow();
//添加列
DevExpress.XtraGrid.Columns.GridColumn col = new DevExpress.XtraGrid.Columns.GridColumn();
col.Caption = "列标题";
col.FieldName = "列字段值";
col.Visible = true;
col.VisibleIndex = gvText.Columns.Count;
gvText.Columns.Add(col);
/// <summary>
/// 获取选定行指定列单元格的值
/// </summary>
/// <param name="str">指定列的列名</param>
/// <returns>单元格的值</returns>
public string GetCellValue(string str) {
int[] pRows = this.gvText.GetSelectedRows();
if (pRows.GetLength(0) > 0){
return gvText.GetRowCellValue(pRows[0], str).ToString();
}
else {
return null;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
DevExpress 控件 GridControl常见用法的更多相关文章
- 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合并表头
写在前面的话: 在园子里逛了有一段时间了,一直想写点东西,但苦于自己的水平有限,生怕写出来的东西浪费了读者的时间.楼主有幸参加了公司DevExpress控件的培训,独乐乐不如众乐乐,特附上Demo以飨 ...
- DevExpress控件-GridControl根据条件改变单元格/行颜色--转载
DevExpress控件-数据控件GridControl,有时我们需要根据特定条件改变符合条件的行或者单元格颜色达到突出显示目的,现在动起鼠标跟我一起操作吧,对的,要达到这个目的您甚至都不用动键盘. ...
- DevExpress控件-GridControl根据条件改变单元格/行颜色(Dev GridControl 单元格着色) z
DevExpress控件-数据控件GridControl,有时我们需要根据特定条件改变符合条件的行或者单元格颜色达到突出显示目的,现在动起鼠标跟我一起操作吧,对的,要达到这个目的您甚至都不用动键盘. ...
- DevExpress控件GridControl使用 z
设置选中行的背景色.而不改变前景色. EnableAppearanceFocusedCell = False, EnableAppearanceFocusedRow = False private v ...
- CListCtlr 控件的常见用法
今天第一次用CListCtrl控件,遇到不少问题,查了许多资料,现将用到的一些东西总结如下: 以下未经说明,listctrl默认view 风格为report 相关类及处理函数 MFC:CListCtr ...
- DevExpress控件 GridControl 单元格编辑 回车
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- devexpress表格控件gridcontrol实现纵向标头
1.devexpress控件gridcontrol中的标头默认是横向的,如果要实现纵向标头应该怎么做呢.通过官网的资料整理了一个简单的案例,给大家分享一下.运行效果图如下: 2.数据绑定代码如下: D ...
随机推荐
- 从外国html5网站上扒来一个鼠标经过的css3 效果,感觉很不错
鼠标经过的时候,感觉有点像一张纸卷上去的感觉. 下面是代码 <div class="main-container types"> <div class=" ...
- WPF 保存文件
private void button2_Click(object sender, RoutedEventArgs e) { var saveFileDialog1 = new SaveFileDia ...
- php练习——打印半金字塔、金字塔、空心金字塔、菱形、空心菱形
半金字塔 金字塔 空心金字塔 菱形 空心菱形
- 基于Lua的清除类游戏算法
最近在开发游戏,用Lua语言.习惯了其它的语言,然后对Lua的一些语法很不习惯. 比如table的元素个数的取值,比switch语句等等. 不过没有办法,还是要运用Lua来写游戏的.看来学C++还真的 ...
- Mac系统安装Lua(转)
下载最新版的lua请点击,然后解压 运行“终端”进入到该文件夹下 ,主要是cd [文件夹名] 在“终端”输入 make macosx (回车) 在“终端”输入 make test (回车) 然后再输入 ...
- failure injection
(1)malloc穷尽的情况: 假设下面的代码是测试代码,里面含有被测函数fmalloc,其中含有一个malloc语句,在一般情况下,是很难走到malloc失败的分支的,因为很难模拟系统内存耗尽的情况 ...
- 计算机视觉的matlab工具箱及MVG等
MATLAB Functions for Multiple View Geometry Peter Kovesi's Matlab functions for Computer Vision Jean ...
- Django1.7.1设置TEMPLATE_DIRS
首先附上我的django工程目录结构: mysite│ db.sqlite3│ manage.py│├─mysite │ settings.py │ urls.py │ views.py ...
- 为什么这么多Python框架
原文:http://bitworking.org/news/Why_so_many_Python_web_frameworks BitWorking This is Joe Gregorio's wr ...
- BZOJ 4009 接水果
Description 风见幽香非常喜欢玩一个叫做osu!的游戏,其中她最喜欢玩的模式就是接水果. 由于她已经DT FC了The big black, 她觉得这个游戏太简单了,于是发明了一个更加难的版 ...