一:第一列显示行号  CustomDrawRowIndicator

this.gridViewDevice.IndicatorWidth = 40;
this.gridViewDevice.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridViewDevice_CustomDrawRowIndicator);

void gridViewDevice_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
{
e.Info.DisplayText = Convert.ToString(Convert.ToInt32(e.RowHandle.ToString()) + 1);
}}

二:不同行显示不同背景颜色  RowStyle

private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
if (e.RowHandle >= 0)
{
String category = view.GetRowCellDisplayText(e.RowHandle, view.Columns["字段名称"]);
  if (category == "显示颜色的条件")
  {
   e.Appearance.BackColor = Color.LightGreen;
   }
}}

三:不同单元格显示不同背景色 RowCellStyle

private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
GridView View = sender as GridView;
if (e.Column.FieldName == "绑定的字段")
{
string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["字段名称"]);
if (category == "满足字段的条件")
{
e.Appearance.BackColor = Color.LightCoral;
e.Appearance.BackColor2 = Color.LightPink;
}}}

四:添加列图标  CustomUnboundColumnData

添加图标列,FieldName设为Image    

Hashtable Images = new Hashtable(); //图标集合

private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column.FieldName == "Image" && e.IsGetData)
{
String  条件 = (String)((DataRowView)e.Row)["查找字段"].ToString();
String fileName = "1.png";

switch (条件)
{
case "1":
fileName = "1.png";
break;
case "2":
fileName = "2.png";
break;
}

if (!Images.ContainsKey(fileName))
{
Image img = null;
try
{
String filePath = System.IO.Path.Combine(Application.StartupPath.ToString(), @"Resource\Icon", fileName);
img = Image.FromFile(filePath);
}
catch{}
Images.Add(fileName, img);
}
e.Value = Images[fileName];
}
}

最新文章

  1. android标题栏下面弹出提示框(一) TextView实现,带动画效果
  2. flag+文件操作
  3. jQuery给标签写入内容
  4. MVVM架构~Knockoutjs系列之对象与对象组合
  5. (转载)ORA-14452:试图创建,更改或删除正在使用的临时表中的索引
  6. Alwayson--SYS.dm_hadr_instance_node_map 返回0行
  7. 让 Terminal/vim 使用 Solarized 配色
  8. poj 3077Rounders(模拟)
  9. 开启Windows Server 2008 R2上帝模式
  10. 转:python webdriver API 之鼠标事件
  11. ie8中支持 password 的 placeholder
  12. shell排序算法
  13. Eclipse安卓开发环境搭建
  14. java常用数据类型使用Day008
  15. 今天我给你们推荐一本书《Linux就该这么学》!!!
  16. SQL 必知必会·笔记<16>使用视图
  17. 并发之synchronized关键字的应用
  18. Oracle 12c pdb的数据泵导入导出
  19. <Spark><Spark Streaming>
  20. Maven知识整理

热门文章

  1. 步进循环语句for
  2. 出错处理完美搭配之perror&exit
  3. Linux shell 脚本攻略之生成任意大小的文件
  4. 小白日记35:kali渗透测试之Web渗透-手动漏洞挖掘(一)-默认安装引发的漏洞
  5. Sorting It All Out
  6. Java中执行外部命令
  7. dem30下载地址
  8. Composer PHP 依赖管理工具
  9. (转)嵌入式学习准备---linux c 文件锁
  10. [转]DataTable用中使用Compute 实现简单的DataTable数据的统计