DevExpress gridView 小结(一)

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

 

 

转载于:https://www.cnblogs.com/cuiliwen/p/3656438.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值