winform - merging datagridview headers

前端 未结 1 1912
野的像风
野的像风 2021-01-26 02:42

I have a problem with merge the datagridview headers in winForm.

I using this code :

void dataGridView1_Paint(object sender, PaintEventArgs e)
    {
               


        
相关标签:
1条回答
  • 2021-01-26 03:21

    I believe the easiest way would be to invalidate merged header's cells every time the datagridview is scrolled. You would need to add a handler to the Scroll event:

    dataGridView1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dataGridView1_Scroll);
    

    Below is scroll event handler implementation:

    private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
    {
        Rectangle rect = Rectangle.Union(
            dataGridView1.GetCellDisplayRectangle(2, -1, true), 
            dataGridView1.GetCellDisplayRectangle(3, -1, true));
        dataGridView1.Invalidate(rect);
    }
    

    hope this helps, regards

    0 讨论(0)
提交回复
热议问题