【问题标题】:DataGridView CellPainting Not Fully Working on ScrollDataGridView CellPainting 不完全适用于滚动
【发布时间】:2009-07-17 15:40:46
【问题描述】:

第一次发帖,但浏览器时间长:)

所以这是我的问题:基本上我有一个用于与用户交互的 datagridview。在所有行中,都有一个“信息”按钮,它会产生一种错觉,即它在其下方添加另一行,所有单元格合并(一个长单元格跨整行)并绘制描述其上方行的文本和图像到“信息单元”。

这很好用,除非当 datagridview 垂直滚动时,然后看起来绘画没有被调用并且网格看起来很乱。有什么想法吗?

这是代码的基本大纲:

private void grid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e){     
    // Loop through and draw all of the open information rows
    foreach (int i in openInfoCells) {
        if (i >= grid.FirstDisplayedCell.RowIndex && 
            i <= (grid.DisplayedRowCount(true) + grid.FirstDisplayedCell.RowIndex)) {

            // Draw Rectangle
            ....

            // Draw Text or Image
            ....
        }
    }
}

【问题讨论】:

    标签: c# datagridview


    【解决方案1】:

    想通了。需要通过执行以下操作为 datagridview 创建双缓冲区:

    class CustomDataGridView : DataGridView {
    
    public CustomDataGridView() {
        base.DoubleBuffered = true;
    }
    }
    

    我也把代码放到RowPostPainting事件里面,把if语句改成:

    if (e.RowIndex == i) { .... }
    

    希望这对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多