Flickering during updates to Controls in WinForms (e.g. DataGridView)

前端 未结 8 1745
悲哀的现实
悲哀的现实 2021-01-05 10:43

In my application I have a DataGridView control that displays data for the selected object. When I select a different object (in a combobox above), I need to update the grid

8条回答
  •  不知归路
    2021-01-05 11:34

    Double buffering won't help here since that only double buffers paint operations, the flickering the OP is seeing is the result of multiple paint operations:

    • Clear control contents -> repaint
    • Clear columns -> repaint
    • Populate new columns -> repaint
    • Add rows -> repaint

    so that's four repaints to update the control, hence the flicker. Unfortunately, not all the standard controls have the BeginUpdate/EndUpdate which would remove all the repaint calls until the EndUpdate is called. Here's what you can do:

    1. Have a different control for each data set and Show/Hide the controls,
    2. Remove the control from its parent, update and then add the control again,
    3. Write your own control.

    Options 1 and 2 would still flicker a bit.

    On the .Net GUI program I'm working on, I created a set of custom controls that eliminated all flicker.

提交回复
热议问题