Question dataGridView1_CellPainting causes flickinger view and effects other control

itchibahn

New member
Joined
Apr 2, 2017
Messages
2
Programming Experience
1-3
I'm using dataGridView1_CellPainting to remove border for merged cells. The view works fine, except for the last line "e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.Single;" statement, which causes view to flicker and strange behavior to another DateTime picker control in another panel. Without that last line, there is no flickering and the other control works fine, but I won't have any border at all. Please help.

C#:
        private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex < 1 || e.ColumnIndex < 0)  return;

            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;

            if (cellTopBorderLines[e.RowIndex, e.ColumnIndex])
                e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None;
            else 
                e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.Single;  // Causes flickering and effects other control
        }
 
Top Bottom