DataGridView的RowPrePaint中的PaintParts不起作用?

时间:2013-05-28 06:34:42

标签: c# winforms datagridview custom-controls

我认为PaintParts指出默认情况下应该绘制哪些部分。它似乎工作正常但是当选择DataGridViewCell时,默认情况下会绘制所有内容。我只想绘制除内容之外的所有内容,这是我的代码:

private void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e){
   e.PaintParts = DataGridViewPaintParts.All & ~DataGridViewPaintParts.ContentForeground;
}

当未选择单元格时,它可以正常工作,但是如果我选择一个单元格,则默认情况下会绘制所有背景和内容。默认/标准DataGridView正常,但我正在处理自定义/第三方DataGridView

你能否向我解释一下这是什么,并给我一些解决方案?

非常感谢!

2 个答案:

答案 0 :(得分:1)

我相信您可以指定以这种方式绘制除Content Background之外的所有内容。

我做到了这一点并且有效。

这应该是您所需要的,除非您只需要特定的单元格来绘制所有的paintPart。

private void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
    e.PaintCells(e.ClipBounds, DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.Border | DataGridViewPaintParts.Background | DataGridViewPaintParts.SelectionBackground);
    e.Handled = true;

    //The e.Handled = true tells the event handler that the event has been completed and that the system doesn't need to do anymore processing.  This line is required to ensure it doesn't process any further(paint more stuff).
}

PS。刚发现这个

C# DataGridViewCheckBoxColumn Hide/Gray-Out

答案 1 :(得分:0)

对于DataGridViewX需要关闭Office 2007增强功能

this.nameofyoudatagridview.PaintEnhancedSelection = false;

设置属性时

这对你有用吗?