datagirdview 的 cellpainting事件如何触发
请教各位一个问题,我想对datagirdview进行单元格合并,网上有很多代码,大多数都利用dataGridView1_CellPainting来实现。
例如下面的代码:
private void dataGridView1_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e)
{
if (this.dataGridView1.Columns["description"].Index == e.ColumnIndex && e.RowIndex >= 0)
{
if (this.nextcol != null & e.ColumnIndex == this.nextcol)
{
e.CellStyle.BackColor = Color.LightBlue;
this.nextcol = null;
}
if (this.nextrow != null & e.RowIndex == nextrow)
{
e.CellStyle.BackColor = Color.LightPink;
this.nextrow = null;
}
if (e.RowIndex != this.dataGridView1.RowCount - 1)
{
if (e.Value.ToString() == this.dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString())
{
e.CellStyle.BackColor = Color.LightPink;
nextrow = e.RowIndex + 1;
}
}
但是如何调用该事件,或者说该事件如何触发呢?有的说是在datagirdview添加数据的时候自动触发,可是我试过了,并没有触发啊?如果是调用,那么 这个 sender和参数e如何指定呢?