一:第一列显示行号  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];
}
}

DevExpress gridView 小结(一)的更多相关文章

  1. DevExpress gridview下拉框的再次研究

    原文:DevExpress gridview下拉框的再次研究 前几天写了一篇关于研究DevExpress gridview下拉框的随笔(DevExpress gridview下拉框repository ...

  2. DevExpress GridView 整理(转)

    DevExpress GridView 那些事儿 1:去除 GridView 头上的 "Drag a column header here to group by that column&q ...

  3. DevExpress GridView 那些事儿

    1:去除 GridView 头上的 "Drag a column header here to group by that column" -->  点击 Run Desig ...

  4. Devexpress Gridview 自定义汇总CustomSummaryCalculate(加权平均)

    Devexpress Gridview 提供了简单的求和,平均等方法,复杂的汇总方法则需要自定义,使用gridview 的CustomSummaryCalculate 事件,根据官网的文档及各论坛案例 ...

  5. DevExpress GridView 整理

    1:去除 GridView 头上的 "Drag a column header here to group by that column" -->  点击 Run Desig ...

  6. Devexpress GridView 列中显示图片

    首先将图片添加到ImageList中 添加GridView中Column void gridView1_CustomUnboundColumnData(object sender, DevExpres ...

  7. Devexpress GridView 数据格式化显示

    gridView1.CustomColumnDisplayText += gridView1_CustomColumnDisplayText; void gridView1_CustomColumnD ...

  8. DevExpress GridView属性说明

    转自http://www.cnblogs.com/-ShiL/archive/2012/06/08/ShiL201206081335.html (一)双击展开,收缩字表 1 Private Sub E ...

  9. DevExpress GridView中加入CheckBox方法

    添加一列,FieldName为 "check",将ColumnEdit 设置为 复选框 样式.gridview1 editable设置为true 将要绑定的DataTable添加列 ...

随机推荐

  1. WebBrowser 禁用脚本错误提示

    public partial class Text : UserControl {        public Text()        {                              ...

  2. 清除XCode缓存和生成文件

    1.Command-Option-Shift-K to clean out the build folder XCode4.2    finder中找到   /Users/apple/Library/ ...

  3. mybatis0211 mybatis和spring整合

    1mybatis和spring整合 1.1 mybaits和spring整合的思路 .让spring管理SqlSessionFactory .让spring管理mapper动态代理对象和dao. 使用 ...

  4. 用scikit-learn实现朴素贝叶斯分类器 转

    原文:http://segmentfault.com/a/1190000002472791 朴素贝叶斯(Naive Bayes Classifier)是一种「天真」的算法(假定所有特征发生概率是独立的 ...

  5. PHP.9-HTML+CSS(三)-CSS样式

    CSS样式 CSS是Cascading Style Sheets的简写,它除了可以轻松设置网页元素的显示位置和格式处,甚至还能产生滤镜,图像淡化,网页淡入淡出的渐变效果.CSS就是要对网页的显示效果实 ...

  6. cocos2d-x lua table与json的转换

    cocos2d-x lua table与json的转换 version: cocos2d-x 3.6 1.引入json库 require("src/cocos/cocos2d/json&qu ...

  7. 获取Spring-boot系统环境变量方法

    public static ConfigurableApplicationContext context = null; public static void main( String[] args ...

  8. SQL Server blocking session

    select * from sys.sysprocesses where blocked>0; 96被95block住了. dbcc INPUTBUFFER(95) dbcc INPUTBUFF ...

  9. CF Tavas and Karafs (二分)

    Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  10. 【转】istringstream、ostringstream、stringstream 类介绍 .

    http://www.cnblogs.com/gamesky/archive/2013/01/09/2852356.html 好吧,懒死我算了