C# XtraGrid的行指示器(RowIndicator)行号以及图标设置

以下是几种对Xtragrid的行指示器的几种操作方法,在实际场景当中,很多都需要用到,直接上效果图和源码

一、基本篇—设置表头行号

1、效果图

2、实现方法

需要对XtraGrid事件CustomDrawRowIndicator 进行操作

1 this.gridView1.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.CustomDrawRowIndicator);
 1 private void CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
 2 {
 3     e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
 4     if (e.Info.IsRowIndicator)
 5     {
 6         if (e.RowHandle >= 0)
 7         {
 8             e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();
 9         }
10         else if (e.RowHandle < 0 && e.RowHandle > -1000)
11         {
12             e.Info.DisplayText = "G" + e.RowHandle.ToString();
13         }
14     }
15 }

二、提升篇—设置表头序号列标题

1、效果图

2、实现方法

同上需要对XtraGrid事件CustomDrawRowIndicator 进行操作

1 this.gridView1.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.CustomDrawRowIndicator);
 1 private void CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
 2 {
 3     if (e.Info.Kind == DevExpress.Utils.Drawing.IndicatorKind.Header)
 4     {
 5         e.Appearance.DrawBackground(e.Cache, e.Bounds);
 6         e.Appearance.DrawString(e.Cache, "序号", e.Bounds);
 7         e.Handled = true;
 8     }
 9     e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
10     if (e.Info.IsRowIndicator)
11     {
12         if (e.RowHandle >= 0)
13         {
14             e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();
15         }
16         else if (e.RowHandle < 0 && e.RowHandle > -1000)
17         {
18             e.Info.DisplayText = "G" + e.RowHandle.ToString();
19         }
20     }
21 }

二、晋级篇—设置表头图标

1、效果图

2、实现方法

同上需要对XtraGrid事件CustomDrawRowIndicator 进行操作

1 this.gridView1.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.CustomDrawRowIndicator);
 1 private void CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
 2 {
 3     if (e.Info.Kind == DevExpress.Utils.Drawing.IndicatorKind.Header)
 4     {
 5         e.Appearance.DrawBackground(e.Cache, e.Bounds);
 6         e.Appearance.DrawString(e.Cache, "序号", e.Bounds); 7 e.Handled = true; 8  } 9 if (e.Info.IsRowIndicator) 10  { 11 if (e.RowHandle >= 0) 12  { 13 GridView gridView = sender as GridView; 14 if (gridView == null) 15 return; 16 17 e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far; 18 e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim(); 19 try 20  { 21 if (Convert.ToDouble(gridView.GetRowCellValue(e.RowHandle, "fTargetSRiseValue")) <= Convert.ToDouble(gridView.GetRowCellValue(e.RowHandle, "fMonitorTargetRiseValue"))) 22  { 23 e.Handled = true; 24  e.Painter.DrawObject(e.Info); 25 e.Graphics.DrawImageUnscaled(imageCollection1.Images[0], e.Bounds.X, e.Bounds.Y + 3);//位置可以微调 26  } 27 if (Convert.ToDouble(gridView.GetRowCellValue(e.RowHandle, "fTargetFallValue")) <= Convert.ToDouble(gridView.GetRowCellValue(e.RowHandle, "fMonitorTargetFallValue"))) 28  { 29 e.Handled = true; 30  e.Painter.DrawObject(e.Info); 31 e.Graphics.DrawImageUnscaled(imageCollection1.Images[1], e.Bounds.X, e.Bounds.Y + 3);//位置可以微调 32  } 33  } 34 catch (Exception) 35  { 36 e.Handled = false; 37  } 38  } 39 else if (e.RowHandle < 0 && e.RowHandle > -1000) 40  { 41 e.Info.DisplayText = "G" + e.RowHandle.ToString(); 42  } 43  } 44 }

PS:如有问题,请留言,未经允许不得私自转载,转载请注明出处:http://www.cnblogs.com/xuliangxing/p/6775438.html

转载于:https://www.cnblogs.com/xuliangxing/p/6775438.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值