我想达到点击BUTTON就重绘DATAGRIDVIEW这个功能,(EXCEL里合并单元格的功能)
现在需要在
private void button1_Click(object sender, EventArgs e)
事件里执行
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
事件1.不知道代码怎么写?请高手赐教
2.或者有其他更好的方法?

解决方案 »

  1.   


    private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    事件的内容
    写成一个方法
    public void ddd()
    {}
    然后两个同时调用它
      

  2.   

    dataGridView1_CellPainting(new object(),new DataGridViewCellPaintingEventArgs());
      

  3.   

    试试dataGridView1.Invalidate()方法.
      

  4.   

    一楼的方法不可行
    private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    {
               if (e.ColumnIndex != -1 && e.RowIndex != -1)
                {
                  dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "";
                }
    }就这么个简单的事件,你可以试试三楼的方法更可笑
    你是要我构造一个DataGridViewCellPaintingEventArgs么四楼的方法正在研究,多谢
      

  5.   

    其实有一个更接近的方法楼主可以用:DataGridView.InvalidateCell 方法
    使 DataGridView 中的某个单元格无效,并强制对它进行重新绘制。
      

  6.   

    比如:
    // Force the cell to repaint itself when the mouse pointer enters it.
    protected override void OnMouseEnter(int rowIndex)
    {
        this.DataGridView.InvalidateCell(this);
    }// Force the cell to repaint itself when the mouse pointer leaves it.
    protected override void OnMouseLeave(int rowIndex)
    {
        this.DataGridView.InvalidateCell(this);
    }
      

  7.   

    dataGridView1.invalidate()方法,来晚了。