2

I thought PaintParts indicates which parts should be painted by default. It seems to work OK but when the DataGridViewCell is selected, everything is painted by default. I just want to paint everything but the Content, here is my code:

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

It works OK when the cell is not selected, however if I select a cell, it's painted by default with all background and content. The default/standard DataGridView works OK but I'm dealing with a custom/third party DataGridView.

Could you please explain to me what that is and give me some solution for that?

Thanks a lot!

4

2 回答 2

1

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

我已经做到了,并且有效。

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

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).
}

附言。刚发现这个

C# DataGridViewCheckBoxColumn 隐藏/灰显

于 2013-05-30T18:58:20.647 回答
0

对于DataGridViewX 需要关闭office 2007 增强

尝试

this.nameofyoudatagridview.PaintEnhancedSelection = false;

当你设置属性

它能为您提供帮助吗?

于 2013-07-30T01:38:59.377 回答