winform - mesclando cabeçalhos de datagridview
Eu tenho um problema com mesclar os cabeçalhos datagridview no winForm.
Eu usando este código:
void dataGridView1_Paint(object sender, PaintEventArgs e)
{
Rectangle r1 = dataGridView1.GetCellDisplayRectangle(2, -1, true);
Rectangle r2 = dataGridView1.GetCellDisplayRectangle(3, -1, true);
r1.X += 1;
r1.Y += 2;
r1.Width += r2.Width - 2;
r1.Height -= 6;
using (SolidBrush br = new SolidBrush(dataGridView1.ColumnHeadersDefaultCellStyle.BackColor))
{
e.Graphics.FillRectangle(br, r1);
}
//draw text
using (SolidBrush br = new SolidBrush(this.dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor))
{
StringFormat sf = new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
};
e.Graphics.DrawString("merged header", dataGridView1.ColumnHeadersDefaultCellStyle.Font, br, r1, sf);
}
}
antes de rolar a grade. está tudo bem, mas depois de rolar o texto do cabeçalho mudou para texto lixo. Por favor, cheque oinstantâneo .
Eu apreciaria que alguém pudesse me ajudar a encontrar uma boa solução.
ali.mz