重新定位DataGridView的错误图标 [英] Reposition the Error Icon of a DataGridView

查看:409
本文介绍了重新定位DataGridView的错误图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据绑定的winform的datagridview。网格不允许进行编辑,只能从两个独立数据源的比较来查看数据不一致,因此可以在数据的记录应用程序中更正修复。如我所做的比较,如果有问题,我设置DataRow的 SetColumnError 属性。问题是数据绑定完成并且网格呈现错误图标覆盖了数据网格单元数据的部分。我已经尝试了几种在SO和网络上找到的各种方法,没有任何工作来移动图标。任何想法?



当网格构建在

后面的代码中时,我已经设置了以下内容 Padding newpadding = new Padding(10,0,30,0)
datagridview.RowTemplet.DefaultCellStyle.Padding = newPadding

但这是结果



解决方案

我发现问题的解决方案。尝试了许多不同的事情后,我遇到了一条代码 here ,解决了问题。



以下是:





以下是:





可以在至少对我而言, CellPainting()事件。我将DataSet数据绑定到一个只读的DataGridView中。 DataSet已经包含了针对DataSet的内部操作运行的错误和错误文本。



关键代码更改是 e.CellBounds.X + 30 这将为X轴增加一个30,允许图像向右推。

  private void dgv_CellPainting(object sender,DataGridViewCellPaintingEventArgs e)
{
e.Paint(e.CellBounds,DataGridViewPaintParts.All&〜DataGridViewPaintParts.ErrorIcon);
if(e.ColumnIndex> -1&& e.RowIndex> -1)
{
if(this.dgv [e.ColumnIndex,e.RowIndex] .ErrorText != string.Empty)
{
Rectangle errorRect = this.dgv [e.ColumnIndex,e.RowIndex] .ErrorIconBounds;
errorRect.X + = e.CellBounds.X + 30;
errorRect.Y + = e.CellBounds.Y;
e.Graphics.DrawImage(gridErrorIcon,errorRect);
}
e.Handled = true;
}
}

内部静态图像gridErrorIcon
{
get {return Properties.Resources.Error; }
}


I have a datagridview on a winform that is databound. The grid does not allow edits it's only to view data inconsistancies from comparison of two separate data sources so the fixes can be corrected in the data's Application of record. As I do the compare I set the SetColumnError property of the DataRow if there is an issue. The problem is when the databinding is complete and the grid renders the Error Icon is covering parts of the datagridcell data. I have tried several various methods found here on SO and on the web and nothing has worked to move the icon. Any thoughts?

I already set the following when the grid is built in the code behind

Padding newpadding = new Padding(10, 0, 30, 0)
datagridview.RowTemplet.DefaultCellStyle.Padding = newPadding

But yet this is the result

解决方案

I found the solution to the problem. After trying many different things I came across a piece of code here that solved the problem.

Here is before:

Here is after:

the changes can be made in the CellPainting() Event at least for me. I was databinding a DataSet into a readonly DataGridView. The DataSet already contained the Errors and ErrorText from an internal operation run against the DataSet.

The key code change is e.CellBounds.X + 30 this pads an extra 30 to the X axis allowing the image to be pushed to the right.

private void dgv_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
    e.Paint(e.CellBounds, DataGridViewPaintParts.All & ~DataGridViewPaintParts.ErrorIcon);
    if (e.ColumnIndex > -1 && e.RowIndex > -1)
    {
        if (this.dgv[e.ColumnIndex, e.RowIndex].ErrorText != string.Empty)
        {
            Rectangle errorRect = this.dgv[e.ColumnIndex, e.RowIndex].ErrorIconBounds;
            errorRect.X += e.CellBounds.X + 30;
            errorRect.Y += e.CellBounds.Y;
            e.Graphics.DrawImage(gridErrorIcon, errorRect);
        }
        e.Handled = true;
    }
}

internal static Image gridErrorIcon
{
    get { return Properties.Resources.Error; }
}

这篇关于重新定位DataGridView的错误图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆