标签:back 选择 效果 alt tor inter else GridView 有关
第一步:在一个窗体中添加一个GridControl控件,如图所示:
第二步:点击控件中的Run Designer,找到Columns,然后再选择要设置进度条的列,设置属性如下:
第三步:点击View,找到事件CustomDrawCell,写如下的代码:
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.RowHandle == gridView1.FocusedRowHandle)
{
e.Appearance.BackColor = Color.CadetBlue;
}
if (e.Column.FieldName == "ZBJD")//为ZBJD这列设置进度条
{
DrProgressBar(e);
e.Handled = true;
DrawEditor(e);
}
}
private void DrProgressBar(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
decimal percent = Convert.ToDecimal(e.CellValue);
int iIndex = 0;
int width = 0;
if (percent < 0.0000001m)
{
iIndex = 1;
}
if (iIndex == 1)
{
width = (int)(100 * Math.Abs(1) * e.Bounds.Width / 100);
}
else
{
width = (int)(100 * Math.Abs(percent) * e.Bounds.Width / 100);
}
Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, width, e.Bounds.Height);
Brush b = Brushes.Green;
if (percent < 1)
{
b = Brushes.Red;
}
else
{
b = Brushes.Green;
}
e.Graphics.FillRectangle(b, rect);
}
private void DrawEditor(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
GridCellInfo cell = e.Cell as GridCellInfo;
Point offset = cell.CellValueRect.Location;
BaseEditPainter pb = cell.ViewInfo.Painter as BaseEditPainter;
AppearanceObject style = cell.ViewInfo.PaintAppearance;
if (!offset.IsEmpty)
cell.ViewInfo.Offset(offset.X, offset.Y);
try
{
pb.Draw(new ControlGraphicsInfoArgs(cell.ViewInfo, e.Cache, cell.Bounds));
}
finally
{
if (!offset.IsEmpty)
{
cell.ViewInfo.Offset(-offset.X, -offset.Y);
}
}
}
最后效果如下:
注意事项:当你的百分比显示不出来的时候,设置进度条这列的ColumnEdit一定不要像其它笔者一样设置一个ProgressBar进度条。当初自己就按照其它笔者的来做,数值总是不显示,一直困扰了我好多天,所以在这里提醒大家一下。在下黎希,以后我会常在博客里写入有关ArcGIS二次开发的内容,希望和大家一起交流学习!
标签:back 选择 效果 alt tor inter else GridView 有关
原文地址:https://www.cnblogs.com/panxinxian/p/9415799.html