以下是几种对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