1

I have a scrollable DataGridView with text and images. But if it contains more rows then fit the screen scrolling doesn't work properly. If you scroll the part of the text that should become hidden remains on top of the new text. So the top and the bottom of my DataGridView contains double text written on top of each other. The middle part is fine, though.

enter image description here

After the creation of the view I resize both the textsize and the cell size. That might be the problem. I honestly don't really know where to start loking for a solution. Only thing I can come up with is to try a repaint on a scroll event. I've tried this similar issue, but it didn't fix it for me. I also see that a lot of people have issues if they paint in the datagridview, but I don't (So please don't mark this as a duplicate of one of those issues). I didn't write this part of the code, but the picture is just passed on by setting it in DataGridViewCellFormattingEventArgs.Value in dgvAlarms_CellFormatting.

When I tried making it DoubleBuffered everything except the headers and the images (that I cut out in the last picture) in the DataGridView turned black like this: enter image description here

Thank you for your help.

Lavandysh
  • 531
  • 1
  • 7
  • 15
  • Just guessing, but making the DGV will certainly improve scrolling performance. It may even help avoid the paint error. – TaW Aug 03 '17 at 10:11
  • I'm sorry, TaW, but what do you mean by "making the DGV"? – Lavandysh Aug 03 '17 at 10:19
  • 1
    Whoops, a typo. I meant 'making the DGV DoubleBuffered'. either by subclassing or via reflection.. [See here for both methods](https://stackoverflow.com/questions/41893708/how-to-prevent-datagridview-from-flickering-when-scrolling-horizontally/41894210#41894210)! – TaW Aug 03 '17 at 10:34
  • Turns out the first time I tried making it DoubleBuffered I did it wrong, but this time everything except the header just becomes black if I turn DGV DoubleBuffered. – Lavandysh Aug 03 '17 at 11:51
  • That sounds totally weird and frankly I have no other idea than that you are still doing something wrong. – TaW Aug 03 '17 at 11:53

1 Answers1

2

Ok, I got It to work with a combination of TaW's anwser in the comment and adding

    e.CellStyle.BackColor = Color.White;
    e.CellStyle.SelectionBackColor = Color.White;

to the beginning of the CellFormatting method. Funny that the backgroundcolor gets set to black if you use the double buffer, but remains white (like I defined) if you I do not.

TaW
  • 53,122
  • 8
  • 69
  • 111
Lavandysh
  • 531
  • 1
  • 7
  • 15